@pax8-cta/core 0.1.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 (226) hide show
  1. package/LICENSE +198 -0
  2. package/dist/auth/device-code-login.d.ts +40 -0
  3. package/dist/auth/device-code-login.d.ts.map +1 -0
  4. package/dist/auth/device-code-login.js +59 -0
  5. package/dist/auth/device-code-login.js.map +1 -0
  6. package/dist/auth/gdap-client.d.ts +81 -0
  7. package/dist/auth/gdap-client.d.ts.map +1 -0
  8. package/dist/auth/gdap-client.js +128 -0
  9. package/dist/auth/gdap-client.js.map +1 -0
  10. package/dist/auth/index.d.ts +19 -0
  11. package/dist/auth/index.d.ts.map +1 -0
  12. package/dist/auth/index.js +19 -0
  13. package/dist/auth/index.js.map +1 -0
  14. package/dist/auth/token-manager.d.ts +54 -0
  15. package/dist/auth/token-manager.d.ts.map +1 -0
  16. package/dist/auth/token-manager.js +150 -0
  17. package/dist/auth/token-manager.js.map +1 -0
  18. package/dist/client.d.ts +27 -0
  19. package/dist/client.d.ts.map +1 -0
  20. package/dist/client.js +27 -0
  21. package/dist/client.js.map +1 -0
  22. package/dist/config/client.d.ts +24 -0
  23. package/dist/config/client.d.ts.map +1 -0
  24. package/dist/config/client.js +18 -0
  25. package/dist/config/client.js.map +1 -0
  26. package/dist/config/index.d.ts +18 -0
  27. package/dist/config/index.d.ts.map +1 -0
  28. package/dist/config/index.js +18 -0
  29. package/dist/config/index.js.map +1 -0
  30. package/dist/config/loader.d.ts +81 -0
  31. package/dist/config/loader.d.ts.map +1 -0
  32. package/dist/config/loader.js +271 -0
  33. package/dist/config/loader.js.map +1 -0
  34. package/dist/config/schema.d.ts +751 -0
  35. package/dist/config/schema.d.ts.map +1 -0
  36. package/dist/config/schema.js +556 -0
  37. package/dist/config/schema.js.map +1 -0
  38. package/dist/constants.d.ts +116 -0
  39. package/dist/constants.d.ts.map +1 -0
  40. package/dist/constants.js +170 -0
  41. package/dist/constants.js.map +1 -0
  42. package/dist/dataverse/agent-resolver.d.ts +98 -0
  43. package/dist/dataverse/agent-resolver.d.ts.map +1 -0
  44. package/dist/dataverse/agent-resolver.js +185 -0
  45. package/dist/dataverse/agent-resolver.js.map +1 -0
  46. package/dist/dataverse/client.d.ts +104 -0
  47. package/dist/dataverse/client.d.ts.map +1 -0
  48. package/dist/dataverse/client.js +272 -0
  49. package/dist/dataverse/client.js.map +1 -0
  50. package/dist/dataverse/connection-refs.d.ts +115 -0
  51. package/dist/dataverse/connection-refs.d.ts.map +1 -0
  52. package/dist/dataverse/connection-refs.js +203 -0
  53. package/dist/dataverse/connection-refs.js.map +1 -0
  54. package/dist/dataverse/index.d.ts +20 -0
  55. package/dist/dataverse/index.d.ts.map +1 -0
  56. package/dist/dataverse/index.js +20 -0
  57. package/dist/dataverse/index.js.map +1 -0
  58. package/dist/dataverse/solution-ops.d.ts +100 -0
  59. package/dist/dataverse/solution-ops.d.ts.map +1 -0
  60. package/dist/dataverse/solution-ops.js +288 -0
  61. package/dist/dataverse/solution-ops.js.map +1 -0
  62. package/dist/errors.d.ts +171 -0
  63. package/dist/errors.d.ts.map +1 -0
  64. package/dist/errors.js +178 -0
  65. package/dist/errors.js.map +1 -0
  66. package/dist/index.d.ts +27 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +40 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/mock/demo-data.d.ts +213 -0
  71. package/dist/mock/demo-data.d.ts.map +1 -0
  72. package/dist/mock/demo-data.js +1096 -0
  73. package/dist/mock/demo-data.js.map +1 -0
  74. package/dist/mock/demo-deployment-store.d.ts +77 -0
  75. package/dist/mock/demo-deployment-store.d.ts.map +1 -0
  76. package/dist/mock/demo-deployment-store.js +85 -0
  77. package/dist/mock/demo-deployment-store.js.map +1 -0
  78. package/dist/powerplatform/admin-client.d.ts +226 -0
  79. package/dist/powerplatform/admin-client.d.ts.map +1 -0
  80. package/dist/powerplatform/admin-client.js +315 -0
  81. package/dist/powerplatform/admin-client.js.map +1 -0
  82. package/dist/powerplatform/index.d.ts +18 -0
  83. package/dist/powerplatform/index.d.ts.map +1 -0
  84. package/dist/powerplatform/index.js +18 -0
  85. package/dist/powerplatform/index.js.map +1 -0
  86. package/dist/powerplatform/tenant-discovery.d.ts +100 -0
  87. package/dist/powerplatform/tenant-discovery.d.ts.map +1 -0
  88. package/dist/powerplatform/tenant-discovery.js +205 -0
  89. package/dist/powerplatform/tenant-discovery.js.map +1 -0
  90. package/dist/preconditions/check.d.ts +41 -0
  91. package/dist/preconditions/check.d.ts.map +1 -0
  92. package/dist/preconditions/check.js +173 -0
  93. package/dist/preconditions/check.js.map +1 -0
  94. package/dist/preconditions/index.d.ts +20 -0
  95. package/dist/preconditions/index.d.ts.map +1 -0
  96. package/dist/preconditions/index.js +20 -0
  97. package/dist/preconditions/index.js.map +1 -0
  98. package/dist/preconditions/loader.d.ts +33 -0
  99. package/dist/preconditions/loader.d.ts.map +1 -0
  100. package/dist/preconditions/loader.js +65 -0
  101. package/dist/preconditions/loader.js.map +1 -0
  102. package/dist/preconditions/schema.d.ts +103 -0
  103. package/dist/preconditions/schema.d.ts.map +1 -0
  104. package/dist/preconditions/schema.js +93 -0
  105. package/dist/preconditions/schema.js.map +1 -0
  106. package/dist/preconditions/types.d.ts +118 -0
  107. package/dist/preconditions/types.d.ts.map +1 -0
  108. package/dist/preconditions/types.js +17 -0
  109. package/dist/preconditions/types.js.map +1 -0
  110. package/dist/queue/index.d.ts +17 -0
  111. package/dist/queue/index.d.ts.map +1 -0
  112. package/dist/queue/index.js +17 -0
  113. package/dist/queue/index.js.map +1 -0
  114. package/dist/queue/memory-queue.d.ts +86 -0
  115. package/dist/queue/memory-queue.d.ts.map +1 -0
  116. package/dist/queue/memory-queue.js +221 -0
  117. package/dist/queue/memory-queue.js.map +1 -0
  118. package/dist/services/audit-log.d.ts +59 -0
  119. package/dist/services/audit-log.d.ts.map +1 -0
  120. package/dist/services/audit-log.js +193 -0
  121. package/dist/services/audit-log.js.map +1 -0
  122. package/dist/services/auth-error-parser.d.ts +36 -0
  123. package/dist/services/auth-error-parser.d.ts.map +1 -0
  124. package/dist/services/auth-error-parser.js +90 -0
  125. package/dist/services/auth-error-parser.js.map +1 -0
  126. package/dist/services/deployment-doctor.d.ts +109 -0
  127. package/dist/services/deployment-doctor.d.ts.map +1 -0
  128. package/dist/services/deployment-doctor.js +476 -0
  129. package/dist/services/deployment-doctor.js.map +1 -0
  130. package/dist/services/deployment-notifications.d.ts +41 -0
  131. package/dist/services/deployment-notifications.d.ts.map +1 -0
  132. package/dist/services/deployment-notifications.js +161 -0
  133. package/dist/services/deployment-notifications.js.map +1 -0
  134. package/dist/services/deployment-progress.d.ts +89 -0
  135. package/dist/services/deployment-progress.d.ts.map +1 -0
  136. package/dist/services/deployment-progress.js +244 -0
  137. package/dist/services/deployment-progress.js.map +1 -0
  138. package/dist/services/deployment-service.d.ts +97 -0
  139. package/dist/services/deployment-service.d.ts.map +1 -0
  140. package/dist/services/deployment-service.js +375 -0
  141. package/dist/services/deployment-service.js.map +1 -0
  142. package/dist/services/drift-analyzer.d.ts +86 -0
  143. package/dist/services/drift-analyzer.d.ts.map +1 -0
  144. package/dist/services/drift-analyzer.js +273 -0
  145. package/dist/services/drift-analyzer.js.map +1 -0
  146. package/dist/services/environment-setup.d.ts +97 -0
  147. package/dist/services/environment-setup.d.ts.map +1 -0
  148. package/dist/services/environment-setup.js +250 -0
  149. package/dist/services/environment-setup.js.map +1 -0
  150. package/dist/services/health-check.d.ts +168 -0
  151. package/dist/services/health-check.d.ts.map +1 -0
  152. package/dist/services/health-check.js +705 -0
  153. package/dist/services/health-check.js.map +1 -0
  154. package/dist/services/index.d.ts +39 -0
  155. package/dist/services/index.d.ts.map +1 -0
  156. package/dist/services/index.js +39 -0
  157. package/dist/services/index.js.map +1 -0
  158. package/dist/services/logger.d.ts +139 -0
  159. package/dist/services/logger.d.ts.map +1 -0
  160. package/dist/services/logger.js +268 -0
  161. package/dist/services/logger.js.map +1 -0
  162. package/dist/services/notification-service.d.ts +55 -0
  163. package/dist/services/notification-service.d.ts.map +1 -0
  164. package/dist/services/notification-service.js +184 -0
  165. package/dist/services/notification-service.js.map +1 -0
  166. package/dist/services/risk-analyzer.d.ts +252 -0
  167. package/dist/services/risk-analyzer.d.ts.map +1 -0
  168. package/dist/services/risk-analyzer.js +866 -0
  169. package/dist/services/risk-analyzer.js.map +1 -0
  170. package/dist/services/rollback.d.ts +57 -0
  171. package/dist/services/rollback.d.ts.map +1 -0
  172. package/dist/services/rollback.js +270 -0
  173. package/dist/services/rollback.js.map +1 -0
  174. package/dist/services/scheduler.d.ts +80 -0
  175. package/dist/services/scheduler.d.ts.map +1 -0
  176. package/dist/services/scheduler.js +350 -0
  177. package/dist/services/scheduler.js.map +1 -0
  178. package/dist/services/secrets.d.ts +31 -0
  179. package/dist/services/secrets.d.ts.map +1 -0
  180. package/dist/services/secrets.js +206 -0
  181. package/dist/services/secrets.js.map +1 -0
  182. package/dist/services/settings-service.d.ts +132 -0
  183. package/dist/services/settings-service.d.ts.map +1 -0
  184. package/dist/services/settings-service.js +378 -0
  185. package/dist/services/settings-service.js.map +1 -0
  186. package/dist/services/solution-diff.d.ts +127 -0
  187. package/dist/services/solution-diff.d.ts.map +1 -0
  188. package/dist/services/solution-diff.js +260 -0
  189. package/dist/services/solution-diff.js.map +1 -0
  190. package/dist/services/solution-mode-detector.d.ts +35 -0
  191. package/dist/services/solution-mode-detector.d.ts.map +1 -0
  192. package/dist/services/solution-mode-detector.js +84 -0
  193. package/dist/services/solution-mode-detector.js.map +1 -0
  194. package/dist/services/tenant-resolver.d.ts +55 -0
  195. package/dist/services/tenant-resolver.d.ts.map +1 -0
  196. package/dist/services/tenant-resolver.js +126 -0
  197. package/dist/services/tenant-resolver.js.map +1 -0
  198. package/dist/services/unmanaged-customizations.d.ts +104 -0
  199. package/dist/services/unmanaged-customizations.d.ts.map +1 -0
  200. package/dist/services/unmanaged-customizations.js +521 -0
  201. package/dist/services/unmanaged-customizations.js.map +1 -0
  202. package/dist/services/url-templater.d.ts +184 -0
  203. package/dist/services/url-templater.d.ts.map +1 -0
  204. package/dist/services/url-templater.js +327 -0
  205. package/dist/services/url-templater.js.map +1 -0
  206. package/dist/services/version-checker.d.ts +108 -0
  207. package/dist/services/version-checker.d.ts.map +1 -0
  208. package/dist/services/version-checker.js +403 -0
  209. package/dist/services/version-checker.js.map +1 -0
  210. package/dist/services/waves.d.ts +90 -0
  211. package/dist/services/waves.d.ts.map +1 -0
  212. package/dist/services/waves.js +222 -0
  213. package/dist/services/waves.js.map +1 -0
  214. package/dist/services/webhook.d.ts +95 -0
  215. package/dist/services/webhook.d.ts.map +1 -0
  216. package/dist/services/webhook.js +244 -0
  217. package/dist/services/webhook.js.map +1 -0
  218. package/dist/utils/deployment-tools.d.ts +110 -0
  219. package/dist/utils/deployment-tools.d.ts.map +1 -0
  220. package/dist/utils/deployment-tools.js +121 -0
  221. package/dist/utils/deployment-tools.js.map +1 -0
  222. package/dist/utils/index.d.ts +17 -0
  223. package/dist/utils/index.d.ts.map +1 -0
  224. package/dist/utils/index.js +18 -0
  225. package/dist/utils/index.js.map +1 -0
  226. package/package.json +49 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Centralized constants for the Pax8 CTA application
18
+ *
19
+ * All magic numbers, timeouts, and configuration values should be defined here
20
+ * to ensure consistency and maintainability across the codebase.
21
+ */
22
+ /** One second in milliseconds */
23
+ export declare const ONE_SECOND_MS = 1000;
24
+ /** One minute in milliseconds */
25
+ export declare const ONE_MINUTE_MS: number;
26
+ /** One hour in milliseconds */
27
+ export declare const ONE_HOUR_MS: number;
28
+ /** One day in milliseconds */
29
+ export declare const ONE_DAY_MS: number;
30
+ /** One week in milliseconds */
31
+ export declare const ONE_WEEK_MS: number;
32
+ /** One month in milliseconds (approximate: 30 days) */
33
+ export declare const ONE_MONTH_MS: number;
34
+ /** Power Platform Administrator role definition ID (Azure AD built-in role) */
35
+ export declare const POWER_PLATFORM_ADMIN_ROLE_ID = "11648597-926c-4cf3-9c36-bcebb0ba8dcc";
36
+ /** Buffer time before token expiry to trigger a refresh (5 minutes) */
37
+ export declare const TOKEN_REFRESH_BUFFER_MS: number;
38
+ /** Default cache TTL for secrets manager (5 minutes) */
39
+ export declare const DEFAULT_SECRETS_CACHE_TTL_MS: number;
40
+ /** Maximum iterations when searching for next cron match (~1 year of minutes) */
41
+ export declare const MAX_SCHEDULE_ITERATIONS: number;
42
+ /** Default max concurrent tenant deployments */
43
+ export declare const DEFAULT_DEPLOYMENT_CONCURRENCY = 3;
44
+ /** Duration to cache health check results (15 minutes) */
45
+ export declare const HEALTH_CHECK_CACHE_DURATION_MS: number;
46
+ /** Default number of retries for health check endpoint requests */
47
+ export declare const DEFAULT_HEALTH_CHECK_RETRIES = 3;
48
+ /** Default expected HTTP status for health check endpoints */
49
+ export declare const DEFAULT_HEALTH_CHECK_EXPECTED_STATUS = 200;
50
+ /** Default number of retries for webhook delivery */
51
+ export declare const DEFAULT_WEBHOOK_RETRIES = 3;
52
+ /** Default concurrency for in-memory queue processing */
53
+ export declare const DEFAULT_MEMORY_QUEUE_CONCURRENCY = 5;
54
+ /** Default max retries for in-memory queue jobs */
55
+ export declare const DEFAULT_MEMORY_QUEUE_RETRIES = 3;
56
+ /** Default retry delay for in-memory queue jobs (5 seconds) */
57
+ export declare const DEFAULT_MEMORY_QUEUE_RETRY_DELAY_MS: number;
58
+ /** Initial delay before retrying failed jobs (10 seconds) */
59
+ export declare const JOB_RETRY_INITIAL_DELAY_MS: number;
60
+ /** How long to keep completed jobs in the queue (24 hours) */
61
+ export declare const COMPLETED_JOB_RETENTION_MS: number;
62
+ /** Maximum number of completed jobs to keep */
63
+ export declare const COMPLETED_JOB_MAX_COUNT = 1000;
64
+ /** How long to keep failed jobs in the queue (7 days) */
65
+ export declare const FAILED_JOB_RETENTION_MS: number;
66
+ /** How long to keep scheduled job records (7 days) */
67
+ export declare const SCHEDULED_JOB_RETENTION_MS: number;
68
+ /** Maximum scheduled jobs to keep */
69
+ export declare const SCHEDULED_JOB_MAX_COUNT = 100;
70
+ /** How long to keep failed scheduled job records (30 days) */
71
+ export declare const SCHEDULED_FAILED_JOB_RETENTION_MS: number;
72
+ /** Default number of retry attempts for deployment jobs */
73
+ export declare const DEFAULT_JOB_ATTEMPTS = 3;
74
+ /** Default polling interval when checking import status (5 seconds) */
75
+ export declare const SOLUTION_IMPORT_POLL_INTERVAL_MS: number;
76
+ /** Default timeout for solution import operations (5 minutes) */
77
+ export declare const SOLUTION_IMPORT_TIMEOUT_MS: number;
78
+ /** Extended timeout for large solution imports (10 minutes) */
79
+ export declare const SOLUTION_IMPORT_EXTENDED_TIMEOUT_MS: number;
80
+ /** Default timeout for rollback operations (10 minutes) */
81
+ export declare const ROLLBACK_TIMEOUT_MS: number;
82
+ /** Default timeout for health check operations (30 seconds) */
83
+ export declare const HEALTH_CHECK_TIMEOUT_MS: number;
84
+ /** Default number of retries for health checks */
85
+ export declare const HEALTH_CHECK_DEFAULT_RETRIES = 2;
86
+ /** Default window for approval (24 hours) */
87
+ export declare const DEFAULT_APPROVAL_WINDOW_MS: number;
88
+ /** Maximum number of audit entries to keep in memory */
89
+ export declare const AUDIT_LOG_MAX_ENTRIES = 10000;
90
+ /** Default rate limit - max requests per duration */
91
+ export declare const DEFAULT_RATE_LIMIT_MAX = 10;
92
+ /** Default rate limit duration (1 minute) */
93
+ export declare const DEFAULT_RATE_LIMIT_DURATION_MS: number;
94
+ /**
95
+ * Default worker concurrency
96
+ * Set to 3 for SQLite safety - better-sqlite3 can struggle with >3-5 concurrent writes
97
+ * For production with high concurrency needs, use PostgreSQL instead
98
+ */
99
+ export declare const DEFAULT_WORKER_CONCURRENCY = 3;
100
+ /** Minimum time to display a deployment step (for UI legibility) */
101
+ export declare const MIN_STEP_DISPLAY_MS = 600;
102
+ /** Delay between starting tenant deployments in live view */
103
+ export declare const TENANT_START_STAGGER_MS = 300;
104
+ /** Maximum concurrent tenant deployments in demo mode */
105
+ export declare const MAX_CONCURRENT_DEMO_TENANTS = 2;
106
+ /** SSE heartbeat interval to keep connection alive (30 seconds) */
107
+ export declare const SSE_HEARTBEAT_INTERVAL_MS: number;
108
+ /** SSE connection timeout - max time before stream is closed (10 minutes) */
109
+ export declare const SSE_TIMEOUT_MS: number;
110
+ /** Default delay between cancellation checks during step processing */
111
+ export declare const CANCELLATION_CHECK_INTERVAL_MS = 200;
112
+ /** One hour in seconds (for duration strings like "1h") */
113
+ export declare const ONE_HOUR_SECONDS = 3600;
114
+ /** One day in seconds */
115
+ export declare const ONE_DAY_SECONDS: number;
116
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAMH,iCAAiC;AACjC,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,iCAAiC;AACjC,eAAO,MAAM,aAAa,QAAqB,CAAC;AAEhD,+BAA+B;AAC/B,eAAO,MAAM,WAAW,QAAqB,CAAC;AAE9C,8BAA8B;AAC9B,eAAO,MAAM,UAAU,QAAmB,CAAC;AAE3C,+BAA+B;AAC/B,eAAO,MAAM,WAAW,QAAiB,CAAC;AAE1C,uDAAuD;AACvD,eAAO,MAAM,YAAY,QAAkB,CAAC;AAM5C,+EAA+E;AAC/E,eAAO,MAAM,4BAA4B,yC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A2D;AAC3D,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAMtD,+DAA+D;AAC/D,eAAO,MAAM,uBAAuB,QAAqB,CAAC;AAE1D,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAM9C,6CAA6C;AAC7C,eAAO,MAAM,0BAA0B,QAAa,CAAC;AAMrD,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAM3C,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,6CAA6C;AAC7C,eAAO,MAAM,8BAA8B,QAAgB,CAAC;AAM5D;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAM5C,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,6DAA6D;AAC7D,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,yDAAyD;AACzD,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,mEAAmE;AACnE,eAAO,MAAM,yBAAyB,QAAqB,CAAC;AAE5D,6EAA6E;AAC7E,eAAO,MAAM,cAAc,QAAqB,CAAC;AAMjD,uEAAuE;AACvE,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAMlD,2DAA2D;AAC3D,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,yBAAyB;AACzB,eAAO,MAAM,eAAe,QAAwB,CAAC"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Centralized constants for the Pax8 CTA application
18
+ *
19
+ * All magic numbers, timeouts, and configuration values should be defined here
20
+ * to ensure consistency and maintainability across the codebase.
21
+ */
22
+ // ============================================================================
23
+ // TIME CONSTANTS (in milliseconds)
24
+ // ============================================================================
25
+ /** One second in milliseconds */
26
+ export const ONE_SECOND_MS = 1000;
27
+ /** One minute in milliseconds */
28
+ export const ONE_MINUTE_MS = 60 * ONE_SECOND_MS;
29
+ /** One hour in milliseconds */
30
+ export const ONE_HOUR_MS = 60 * ONE_MINUTE_MS;
31
+ /** One day in milliseconds */
32
+ export const ONE_DAY_MS = 24 * ONE_HOUR_MS;
33
+ /** One week in milliseconds */
34
+ export const ONE_WEEK_MS = 7 * ONE_DAY_MS;
35
+ /** One month in milliseconds (approximate: 30 days) */
36
+ export const ONE_MONTH_MS = 30 * ONE_DAY_MS;
37
+ // ============================================================================
38
+ // AZURE AD / GDAP ROLE IDS
39
+ // ============================================================================
40
+ /** Power Platform Administrator role definition ID (Azure AD built-in role) */
41
+ export const POWER_PLATFORM_ADMIN_ROLE_ID = "11648597-926c-4cf3-9c36-bcebb0ba8dcc";
42
+ // ============================================================================
43
+ // TOKEN MANAGEMENT
44
+ // ============================================================================
45
+ /** Buffer time before token expiry to trigger a refresh (5 minutes) */
46
+ export const TOKEN_REFRESH_BUFFER_MS = 5 * ONE_MINUTE_MS;
47
+ /** Default cache TTL for secrets manager (5 minutes) */
48
+ export const DEFAULT_SECRETS_CACHE_TTL_MS = 5 * ONE_MINUTE_MS;
49
+ // ============================================================================
50
+ // SCHEDULER
51
+ // ============================================================================
52
+ /** Maximum iterations when searching for next cron match (~1 year of minutes) */
53
+ export const MAX_SCHEDULE_ITERATIONS = 366 * 24 * 60;
54
+ // ============================================================================
55
+ // DEPLOYMENT
56
+ // ============================================================================
57
+ /** Default max concurrent tenant deployments */
58
+ export const DEFAULT_DEPLOYMENT_CONCURRENCY = 3;
59
+ // ============================================================================
60
+ // HEALTH CHECK
61
+ // ============================================================================
62
+ /** Duration to cache health check results (15 minutes) */
63
+ export const HEALTH_CHECK_CACHE_DURATION_MS = 15 * ONE_MINUTE_MS;
64
+ /** Default number of retries for health check endpoint requests */
65
+ export const DEFAULT_HEALTH_CHECK_RETRIES = 3;
66
+ /** Default expected HTTP status for health check endpoints */
67
+ export const DEFAULT_HEALTH_CHECK_EXPECTED_STATUS = 200;
68
+ // ============================================================================
69
+ // WEBHOOK
70
+ // ============================================================================
71
+ /** Default number of retries for webhook delivery */
72
+ export const DEFAULT_WEBHOOK_RETRIES = 3;
73
+ // ============================================================================
74
+ // MEMORY QUEUE
75
+ // ============================================================================
76
+ /** Default concurrency for in-memory queue processing */
77
+ export const DEFAULT_MEMORY_QUEUE_CONCURRENCY = 5;
78
+ /** Default max retries for in-memory queue jobs */
79
+ export const DEFAULT_MEMORY_QUEUE_RETRIES = 3;
80
+ /** Default retry delay for in-memory queue jobs (5 seconds) */
81
+ export const DEFAULT_MEMORY_QUEUE_RETRY_DELAY_MS = 5 * ONE_SECOND_MS;
82
+ // ============================================================================
83
+ // QUEUE CONFIGURATION
84
+ // ============================================================================
85
+ /** Initial delay before retrying failed jobs (10 seconds) */
86
+ export const JOB_RETRY_INITIAL_DELAY_MS = 10 * ONE_SECOND_MS;
87
+ /** How long to keep completed jobs in the queue (24 hours) */
88
+ export const COMPLETED_JOB_RETENTION_MS = ONE_DAY_MS;
89
+ /** Maximum number of completed jobs to keep */
90
+ export const COMPLETED_JOB_MAX_COUNT = 1000;
91
+ /** How long to keep failed jobs in the queue (7 days) */
92
+ export const FAILED_JOB_RETENTION_MS = ONE_WEEK_MS;
93
+ /** How long to keep scheduled job records (7 days) */
94
+ export const SCHEDULED_JOB_RETENTION_MS = ONE_WEEK_MS;
95
+ /** Maximum scheduled jobs to keep */
96
+ export const SCHEDULED_JOB_MAX_COUNT = 100;
97
+ /** How long to keep failed scheduled job records (30 days) */
98
+ export const SCHEDULED_FAILED_JOB_RETENTION_MS = ONE_MONTH_MS;
99
+ /** Default number of retry attempts for deployment jobs */
100
+ export const DEFAULT_JOB_ATTEMPTS = 3;
101
+ // ============================================================================
102
+ // SOLUTION IMPORT/EXPORT
103
+ // ============================================================================
104
+ /** Default polling interval when checking import status (5 seconds) */
105
+ export const SOLUTION_IMPORT_POLL_INTERVAL_MS = 5 * ONE_SECOND_MS;
106
+ /** Default timeout for solution import operations (5 minutes) */
107
+ export const SOLUTION_IMPORT_TIMEOUT_MS = 5 * ONE_MINUTE_MS;
108
+ /** Extended timeout for large solution imports (10 minutes) */
109
+ export const SOLUTION_IMPORT_EXTENDED_TIMEOUT_MS = 10 * ONE_MINUTE_MS;
110
+ /** Default timeout for rollback operations (10 minutes) */
111
+ export const ROLLBACK_TIMEOUT_MS = 10 * ONE_MINUTE_MS;
112
+ // ============================================================================
113
+ // HEALTH CHECK
114
+ // ============================================================================
115
+ /** Default timeout for health check operations (30 seconds) */
116
+ export const HEALTH_CHECK_TIMEOUT_MS = 30 * ONE_SECOND_MS;
117
+ /** Default number of retries for health checks */
118
+ export const HEALTH_CHECK_DEFAULT_RETRIES = 2;
119
+ // ============================================================================
120
+ // APPROVAL WORKFLOW
121
+ // ============================================================================
122
+ /** Default window for approval (24 hours) */
123
+ export const DEFAULT_APPROVAL_WINDOW_MS = ONE_DAY_MS;
124
+ // ============================================================================
125
+ // AUDIT LOG
126
+ // ============================================================================
127
+ /** Maximum number of audit entries to keep in memory */
128
+ export const AUDIT_LOG_MAX_ENTRIES = 10000;
129
+ // ============================================================================
130
+ // API RATE LIMITING
131
+ // ============================================================================
132
+ /** Default rate limit - max requests per duration */
133
+ export const DEFAULT_RATE_LIMIT_MAX = 10;
134
+ /** Default rate limit duration (1 minute) */
135
+ export const DEFAULT_RATE_LIMIT_DURATION_MS = ONE_MINUTE_MS;
136
+ // ============================================================================
137
+ // WORKER CONFIGURATION
138
+ // ============================================================================
139
+ /**
140
+ * Default worker concurrency
141
+ * Set to 3 for SQLite safety - better-sqlite3 can struggle with >3-5 concurrent writes
142
+ * For production with high concurrency needs, use PostgreSQL instead
143
+ */
144
+ export const DEFAULT_WORKER_CONCURRENCY = 3;
145
+ // ============================================================================
146
+ // SSE/LIVE UPDATES
147
+ // ============================================================================
148
+ /** Minimum time to display a deployment step (for UI legibility) */
149
+ export const MIN_STEP_DISPLAY_MS = 600;
150
+ /** Delay between starting tenant deployments in live view */
151
+ export const TENANT_START_STAGGER_MS = 300;
152
+ /** Maximum concurrent tenant deployments in demo mode */
153
+ export const MAX_CONCURRENT_DEMO_TENANTS = 2;
154
+ /** SSE heartbeat interval to keep connection alive (30 seconds) */
155
+ export const SSE_HEARTBEAT_INTERVAL_MS = 30 * ONE_SECOND_MS;
156
+ /** SSE connection timeout - max time before stream is closed (10 minutes) */
157
+ export const SSE_TIMEOUT_MS = 10 * ONE_MINUTE_MS;
158
+ // ============================================================================
159
+ // RETRY CONFIGURATION
160
+ // ============================================================================
161
+ /** Default delay between cancellation checks during step processing */
162
+ export const CANCELLATION_CHECK_INTERVAL_MS = 200;
163
+ // ============================================================================
164
+ // TIME DURATIONS (in seconds, for compatibility with parseDuration)
165
+ // ============================================================================
166
+ /** One hour in seconds (for duration strings like "1h") */
167
+ export const ONE_HOUR_SECONDS = 3600;
168
+ /** One day in seconds */
169
+ export const ONE_DAY_SECONDS = 24 * ONE_HOUR_SECONDS;
170
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH,+EAA+E;AAC/E,mCAAmC;AACnC,+EAA+E;AAE/E,iCAAiC;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAElC,iCAAiC;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,GAAG,aAAa,CAAC;AAEhD,+BAA+B;AAC/B,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,GAAG,aAAa,CAAC;AAE9C,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M,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { DataverseClient, SolutionRecord } from "./client.js";
17
+ /**
18
+ * Bot (Copilot) record from Dataverse
19
+ */
20
+ export interface BotRecord {
21
+ botid: string;
22
+ name: string;
23
+ schemaname?: string;
24
+ solutionid?: string;
25
+ statecode: number;
26
+ statuscode: number;
27
+ createdon: string;
28
+ modifiedon: string;
29
+ componentstate?: number;
30
+ }
31
+ /**
32
+ * Parsed M365 agent URL info
33
+ */
34
+ export interface ParsedAgentUrl {
35
+ titleId: string;
36
+ possibleBotId: string | null;
37
+ prefix: string | null;
38
+ originalUrl: string;
39
+ }
40
+ /**
41
+ * Resolved agent info with solution details
42
+ */
43
+ export interface ResolvedAgent {
44
+ bot: BotRecord;
45
+ solution: SolutionRecord;
46
+ titleId: string;
47
+ }
48
+ /**
49
+ * Resolves M365 agent URLs to Dataverse solutions for export
50
+ */
51
+ export declare class AgentResolver {
52
+ private client;
53
+ constructor(client: DataverseClient);
54
+ /**
55
+ * Parse an M365 agent URL to extract the titleId
56
+ *
57
+ * URL format: https://m365.cloud.microsoft/chat/?titleId=P_8cfc4e6f-267e-db15-c6e7-3fc47a54f61e
58
+ *
59
+ * The titleId appears to be formatted as: {prefix}_{guid}
60
+ * Where prefix might indicate the type (P = Published?)
61
+ */
62
+ parseAgentUrl(url: string): ParsedAgentUrl;
63
+ /**
64
+ * Query all bots in the environment
65
+ */
66
+ listBots(): Promise<BotRecord[]>;
67
+ /**
68
+ * Get a bot by its ID
69
+ */
70
+ getBotById(botId: string): Promise<BotRecord | null>;
71
+ /**
72
+ * Search for a bot by name (partial match)
73
+ */
74
+ searchBotsByName(searchTerm: string): Promise<BotRecord[]>;
75
+ /**
76
+ * Find the solution containing a specific bot
77
+ *
78
+ * Uses the solutioncomponent table to find which solution contains the bot
79
+ */
80
+ findSolutionForBot(botId: string): Promise<SolutionRecord | null>;
81
+ /**
82
+ * Resolve an M365 agent URL to its containing solution
83
+ *
84
+ * This tries multiple strategies:
85
+ * 1. Direct bot ID lookup (if titleId contains a valid GUID)
86
+ * 2. Search all bots for a matching ID pattern
87
+ * 3. Query solution components
88
+ */
89
+ resolveUrlToSolution(url: string): Promise<ResolvedAgent>;
90
+ /**
91
+ * List all bots with their containing solutions
92
+ */
93
+ listBotsWithSolutions(): Promise<Array<{
94
+ bot: BotRecord;
95
+ solution: SolutionRecord | null;
96
+ }>>;
97
+ }
98
+ //# sourceMappingURL=agent-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-resolver.d.ts","sourceRoot":"","sources":["../../src/dataverse/agent-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG9D;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAaD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,SAAS,CAAC;IACf,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAE3C;;;;;;;OAOG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc;IAsC1C;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAQtC;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAkB1D;;OAEG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAShE;;;;OAIG;IACG,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IA6BvE;;;;;;;OAOG;IACG,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA+C/D;;OAEG;IACG,qBAAqB,IAAI,OAAO,CACpC,KAAK,CAAC;QAAE,GAAG,EAAE,SAAS,CAAC;QAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAA;KAAE,CAAC,CAC3D;CAWF"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { AgentResolutionError, ErrorCode, DataverseApiError } from "../errors.js";
17
+ // Component types for bots in solutioncomponent table
18
+ // (unused constant kept for documentation - actual values are in componentTypes array)
19
+ /**
20
+ * Resolves M365 agent URLs to Dataverse solutions for export
21
+ */
22
+ export class AgentResolver {
23
+ client;
24
+ constructor(client) {
25
+ this.client = client;
26
+ }
27
+ /**
28
+ * Parse an M365 agent URL to extract the titleId
29
+ *
30
+ * URL format: https://m365.cloud.microsoft/chat/?titleId=P_8cfc4e6f-267e-db15-c6e7-3fc47a54f61e
31
+ *
32
+ * The titleId appears to be formatted as: {prefix}_{guid}
33
+ * Where prefix might indicate the type (P = Published?)
34
+ */
35
+ parseAgentUrl(url) {
36
+ const parsed = new URL(url);
37
+ const titleId = parsed.searchParams.get("titleId");
38
+ if (!titleId) {
39
+ throw new AgentResolutionError(ErrorCode.AGENT_URL_INVALID, "No titleId parameter found in URL", { agentUrl: url });
40
+ }
41
+ // Try to extract the GUID portion from titleId
42
+ // Format appears to be: P_8cfc4e6f-267e-db15-c6e7-3fc47a54f61e
43
+ const parts = titleId.split("_");
44
+ let prefix = null;
45
+ let possibleBotId = null;
46
+ if (parts.length >= 2) {
47
+ prefix = parts[0];
48
+ // The remaining parts might form a GUID (with dashes already present)
49
+ possibleBotId = parts.slice(1).join("_");
50
+ // Validate it looks like a GUID
51
+ const guidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
52
+ if (!guidPattern.test(possibleBotId)) {
53
+ possibleBotId = null;
54
+ }
55
+ }
56
+ return {
57
+ titleId,
58
+ possibleBotId,
59
+ prefix,
60
+ originalUrl: url,
61
+ };
62
+ }
63
+ /**
64
+ * Query all bots in the environment
65
+ */
66
+ async listBots() {
67
+ const result = await this.client.get("/bots", {
68
+ $select: "botid,name,schemaname,statecode,statuscode,createdon,modifiedon,componentstate",
69
+ $orderby: "modifiedon desc",
70
+ });
71
+ return result.value;
72
+ }
73
+ /**
74
+ * Get a bot by its ID
75
+ */
76
+ async getBotById(botId) {
77
+ try {
78
+ const result = await this.client.get(`/bots(${botId})`, {
79
+ $select: "botid,name,schemaname,statecode,statuscode,createdon,modifiedon,componentstate",
80
+ });
81
+ return result;
82
+ }
83
+ catch (error) {
84
+ // Bot not found - check by typed error code or status code
85
+ if ((error instanceof DataverseApiError && error.statusCode === 404) ||
86
+ (error instanceof Error && error.message.includes("404"))) {
87
+ return null;
88
+ }
89
+ throw error;
90
+ }
91
+ }
92
+ /**
93
+ * Search for a bot by name (partial match)
94
+ */
95
+ async searchBotsByName(searchTerm) {
96
+ const result = await this.client.get("/bots", {
97
+ $select: "botid,name,schemaname,statecode,statuscode,createdon,modifiedon,componentstate",
98
+ $filter: `contains(name, '${searchTerm}')`,
99
+ $orderby: "modifiedon desc",
100
+ });
101
+ return result.value;
102
+ }
103
+ /**
104
+ * Find the solution containing a specific bot
105
+ *
106
+ * Uses the solutioncomponent table to find which solution contains the bot
107
+ */
108
+ async findSolutionForBot(botId) {
109
+ // Search solutioncomponents for this bot
110
+ // Try multiple component types as the exact type for bots varies
111
+ const componentTypes = [10109, 10034, 300]; // Different possible bot component types
112
+ for (const componentType of componentTypes) {
113
+ const result = await this.client.get("/solutioncomponents", {
114
+ $select: "solutioncomponentid,componenttype,objectid,_solutionid_value",
115
+ $filter: `objectid eq '${botId}' and componenttype eq ${componentType}`,
116
+ });
117
+ if (result.value.length > 0) {
118
+ const component = result.value[0];
119
+ const solution = await this.client.get(`/solutions(${component._solutionid_value})`, {
120
+ $select: "solutionid,uniquename,friendlyname,version,ismanaged",
121
+ });
122
+ return solution;
123
+ }
124
+ }
125
+ return null;
126
+ }
127
+ /**
128
+ * Resolve an M365 agent URL to its containing solution
129
+ *
130
+ * This tries multiple strategies:
131
+ * 1. Direct bot ID lookup (if titleId contains a valid GUID)
132
+ * 2. Search all bots for a matching ID pattern
133
+ * 3. Query solution components
134
+ */
135
+ async resolveUrlToSolution(url) {
136
+ const parsed = this.parseAgentUrl(url);
137
+ // Strategy 1: Try direct bot ID lookup
138
+ if (parsed.possibleBotId) {
139
+ const bot = await this.getBotById(parsed.possibleBotId);
140
+ if (bot) {
141
+ const solution = await this.findSolutionForBot(bot.botid);
142
+ if (solution) {
143
+ return { bot, solution, titleId: parsed.titleId };
144
+ }
145
+ }
146
+ }
147
+ // Strategy 2: List all bots and try to match by ID pattern
148
+ const allBots = await this.listBots();
149
+ // Try to find a bot whose ID matches part of the titleId
150
+ for (const bot of allBots) {
151
+ if (parsed.titleId.toLowerCase().includes(bot.botid.toLowerCase().replace(/-/g, ""))) {
152
+ const solution = await this.findSolutionForBot(bot.botid);
153
+ if (solution) {
154
+ return { bot, solution, titleId: parsed.titleId };
155
+ }
156
+ }
157
+ }
158
+ // Strategy 3: Try matching by name containing the titleId prefix
159
+ if (parsed.prefix) {
160
+ const matchingBots = await this.searchBotsByName(parsed.prefix);
161
+ for (const bot of matchingBots) {
162
+ const solution = await this.findSolutionForBot(bot.botid);
163
+ if (solution) {
164
+ return { bot, solution, titleId: parsed.titleId };
165
+ }
166
+ }
167
+ }
168
+ throw new AgentResolutionError(ErrorCode.AGENT_RESOLUTION_FAILED, `Could not resolve agent URL to a solution. titleId: ${parsed.titleId}\n` +
169
+ `Tried: direct lookup, pattern matching across ${allBots.length} bots.\n` +
170
+ `The titleId format may require M365 Graph API access to resolve.`, { agentUrl: url });
171
+ }
172
+ /**
173
+ * List all bots with their containing solutions
174
+ */
175
+ async listBotsWithSolutions() {
176
+ const bots = await this.listBots();
177
+ const results = [];
178
+ for (const bot of bots) {
179
+ const solution = await this.findSolutionForBot(bot.botid);
180
+ results.push({ bot, solution });
181
+ }
182
+ return results;
183
+ }
184
+ }
185
+ //# sourceMappingURL=agent-resolver.js.map
@@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