@erxes/api-shared 3.2.20-1 → 3.2.20-3

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 (25) hide show
  1. package/core-modules/dist/erxes-api-shared-core-modules.cjs.dev.js +1 -1
  2. package/core-modules/dist/erxes-api-shared-core-modules.cjs.prod.js +1 -1
  3. package/core-modules/dist/erxes-api-shared-core-modules.esm.js +2 -2
  4. package/dist/declarations/src/utils/saas/global-profile-v2.d.ts +32 -0
  5. package/dist/declarations/src/utils/saas/global-profile-v2.d.ts.map +1 -0
  6. package/dist/declarations/src/utils/saas/index.d.ts +1 -0
  7. package/dist/declarations/src/utils/saas/index.d.ts.map +1 -1
  8. package/dist/declarations/src/utils/saas/saas-mongo-connection.d.ts.map +1 -1
  9. package/dist/declarations/src/utils/saas/types.d.ts +2 -0
  10. package/dist/declarations/src/utils/saas/types.d.ts.map +1 -1
  11. package/dist/declarations/src/utils/service-discovery.d.ts.map +1 -1
  12. package/dist/{start-plugin-89fa2bd2.cjs.dev.js → start-plugin-7dc096bc.cjs.dev.js} +351 -16
  13. package/dist/{start-plugin-6e76556c.esm.js → start-plugin-a2f6eca9.esm.js} +350 -20
  14. package/dist/{start-plugin-576e707d.cjs.prod.js → start-plugin-b095acca.cjs.prod.js} +351 -16
  15. package/package.json +1 -1
  16. package/src/utils/saas/definition.ts +6 -0
  17. package/src/utils/saas/global-profile-v2.test.ts +81 -0
  18. package/src/utils/saas/global-profile-v2.ts +203 -0
  19. package/src/utils/saas/index.ts +1 -0
  20. package/src/utils/saas/saas-mongo-connection.ts +19 -1
  21. package/src/utils/saas/types.ts +3 -0
  22. package/src/utils/service-discovery.ts +15 -1
  23. package/utils/dist/erxes-api-shared-utils.cjs.dev.js +6 -1
  24. package/utils/dist/erxes-api-shared-utils.cjs.prod.js +6 -1
  25. package/utils/dist/erxes-api-shared-utils.esm.js +2 -2
@@ -0,0 +1,203 @@
1
+ import { getEnv } from '../utils';
2
+ import { redis } from '../redis';
3
+ import { IOrganization } from './types';
4
+
5
+ /*
6
+ * Organizations created on dashboard.erxes.io (the v2 global profile) carry
7
+ * gpStatus 'new'. Their plugins come from Stripe, not from `charge`:
8
+ * - every item on the organization's subscriptions while it is active, trialing
9
+ * or past due. A removed item drops to quantity 0 but stays until the period
10
+ * ends; the v2 profile stamps that date on the item as `ends_at` metadata.
11
+ * - every plugin inside a bundle item (`plugins` in the price metadata).
12
+ * - plugins the organization has without a Stripe item (free plans, always-free
13
+ * plugins, admin gifts), kept in the customer's `free_plugins` metadata.
14
+ * Organizations without gpStatus, or with 'old', are untouched.
15
+ */
16
+
17
+ export const GP_STATUS = { OLD: 'old', NEW: 'new' } as const;
18
+
19
+ export const isGlobalProfileV2 = (
20
+ organization?: Partial<IOrganization> | null,
21
+ ): boolean => organization?.gpStatus === GP_STATUS.NEW;
22
+
23
+ const STRIPE_API = 'https://api.stripe.com/v1';
24
+ const LIVE_STATUSES = ['active', 'trialing', 'past_due'];
25
+ const FRESH_SECONDS = 60;
26
+ // Served when Stripe can't be reached, so a short outage doesn't empty workspaces.
27
+ const STALE_SECONDS = 24 * 60 * 60;
28
+
29
+ type StripeMetadata = Record<string, string | undefined>;
30
+
31
+ type StripeItem = {
32
+ quantity?: number;
33
+ metadata?: StripeMetadata;
34
+ price?: {
35
+ metadata?: StripeMetadata;
36
+ product?: string | { metadata?: StripeMetadata; deleted?: boolean };
37
+ };
38
+ };
39
+
40
+ type StripeSubscription = {
41
+ status: string;
42
+ items?: { data: StripeItem[] };
43
+ };
44
+
45
+ const list = (value?: string) =>
46
+ (value || '')
47
+ .split(',')
48
+ .map((code) => code.trim())
49
+ .filter(Boolean);
50
+
51
+ const stripeGet = async <T>(path: string): Promise<T> => {
52
+ const key = getEnv({ name: 'GP2_STRIPE_SECRET_KEY' });
53
+
54
+ if (!key) {
55
+ throw new Error('GP2_STRIPE_SECRET_KEY is not configured');
56
+ }
57
+
58
+ const response = await fetch(`${STRIPE_API}${path}`, {
59
+ headers: { Authorization: `Bearer ${key}` },
60
+ signal: AbortSignal.timeout(8000),
61
+ });
62
+
63
+ if (!response.ok) {
64
+ throw new Error(`Stripe ${path.split('?')[0]}: ${response.status}`);
65
+ }
66
+
67
+ return response.json() as Promise<T>;
68
+ };
69
+
70
+ /** Plugin codes one subscription item grants right now. */
71
+ export const pluginsOfStripeItem = (
72
+ item: StripeItem,
73
+ nowSeconds = Date.now() / 1000,
74
+ ): string[] => {
75
+ const endsAt = Number(item.metadata?.ends_at || 0);
76
+ const entitled = (item.quantity ?? 0) > 0 || endsAt > nowSeconds;
77
+
78
+ if (!entitled) {
79
+ return [];
80
+ }
81
+
82
+ const product =
83
+ typeof item.price?.product === 'object' ? item.price.product : undefined;
84
+ const metadata = {
85
+ ...(product?.metadata || {}),
86
+ ...(item.price?.metadata || {}),
87
+ };
88
+
89
+ if (metadata.kind === 'bundle') {
90
+ return list(metadata.plugins);
91
+ }
92
+
93
+ return metadata.plugin_code ? [metadata.plugin_code] : [];
94
+ };
95
+
96
+ /** Plugin codes granted by a customer's free list and live subscriptions. */
97
+ export const pluginsFromStripe = (
98
+ freePlugins: string | undefined,
99
+ subscriptions: StripeSubscription[],
100
+ nowSeconds = Date.now() / 1000,
101
+ ): string[] => {
102
+ const plugins = new Set(list(freePlugins));
103
+
104
+ for (const subscription of subscriptions) {
105
+ if (!LIVE_STATUSES.includes(subscription.status)) {
106
+ continue;
107
+ }
108
+
109
+ for (const item of subscription.items?.data || []) {
110
+ pluginsOfStripeItem(item, nowSeconds).forEach((code) =>
111
+ plugins.add(code),
112
+ );
113
+ }
114
+ }
115
+
116
+ return [...plugins];
117
+ };
118
+
119
+ const fetchPlugins = async (customerId: string): Promise<string[]> => {
120
+ const customer = await stripeGet<{
121
+ deleted?: boolean;
122
+ metadata?: StripeMetadata;
123
+ }>(`/customers/${encodeURIComponent(customerId)}`);
124
+
125
+ if (customer.deleted) {
126
+ return [];
127
+ }
128
+
129
+ // Prices come with each item. Stripe can't expand item products from a list
130
+ // (more than 4 levels), so a product is fetched only when its price has no
131
+ // plugin metadata of its own.
132
+ const subscriptions = await stripeGet<{ data: StripeSubscription[] }>(
133
+ `/subscriptions?customer=${encodeURIComponent(
134
+ customerId,
135
+ )}&status=all&limit=100`,
136
+ );
137
+
138
+ const products = new Map<string, { metadata?: StripeMetadata }>();
139
+
140
+ for (const subscription of subscriptions.data) {
141
+ for (const item of subscription.items?.data || []) {
142
+ const price = item.price;
143
+ const product = price?.product;
144
+
145
+ if (price && !price.metadata?.kind && typeof product === 'string') {
146
+ if (!products.has(product)) {
147
+ products.set(
148
+ product,
149
+ await stripeGet<{ metadata?: StripeMetadata }>(
150
+ `/products/${encodeURIComponent(product)}`,
151
+ ),
152
+ );
153
+ }
154
+
155
+ price.product = products.get(product);
156
+ }
157
+ }
158
+ }
159
+
160
+ return pluginsFromStripe(customer.metadata?.free_plugins, subscriptions.data);
161
+ };
162
+
163
+ /** Plugin codes a v2 organization may use. Cached for a minute per organization. */
164
+ export const getGlobalProfileV2Plugins = async (
165
+ organization: Partial<IOrganization>,
166
+ ): Promise<string[]> => {
167
+ const customerId = organization.gpStripeCustomerId;
168
+
169
+ if (!customerId) {
170
+ return [];
171
+ }
172
+
173
+ const freshKey = `gp2_plugins:${customerId}`;
174
+ const staleKey = `gp2_plugins_stale:${customerId}`;
175
+
176
+ const cached = await redis.get(freshKey).catch(() => null);
177
+
178
+ if (cached) {
179
+ return JSON.parse(cached);
180
+ }
181
+
182
+ try {
183
+ const plugins = await fetchPlugins(customerId);
184
+ const value = JSON.stringify(plugins);
185
+
186
+ await Promise.all([
187
+ redis.set(freshKey, value, 'EX', FRESH_SECONDS),
188
+ redis.set(staleKey, value, 'EX', STALE_SECONDS),
189
+ ]).catch(() => undefined);
190
+
191
+ return plugins;
192
+ } catch (error) {
193
+ console.error(
194
+ `[gp2] plugins for ${organization.subdomain}: ${
195
+ (error as Error).message
196
+ }`,
197
+ );
198
+
199
+ const stale = await redis.get(staleKey).catch(() => null);
200
+
201
+ return stale ? JSON.parse(stale) : [];
202
+ }
203
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './saas-mongo-connection';
2
2
  export * from './types';
3
+ export * from './global-profile-v2';
@@ -124,7 +124,25 @@ export const getSaasOrgsCache = async ({
124
124
  }
125
125
 
126
126
  if (subdomain) {
127
- return organizations.find((org) => org.subdomain === subdomain);
127
+ const cached = organizations.find((org) => org.subdomain === subdomain);
128
+
129
+ if (cached) {
130
+ return cached;
131
+ }
132
+
133
+ // dashboard.erxes.io creates organizations without access to this cache:
134
+ // read a missing subdomain from the database and rebuild the cache if found.
135
+ await getSaasCoreConnection();
136
+
137
+ const organization = await coreModelOrganizations
138
+ .findOne({ subdomain })
139
+ .lean();
140
+
141
+ if (organization) {
142
+ await redis.set('core_organizations', '');
143
+ }
144
+
145
+ return organization || undefined;
128
146
  }
129
147
 
130
148
  if (excludeSubdomains) {
@@ -58,6 +58,9 @@ export interface IOrganization {
58
58
  // Legacy single domain, moved into helpCenterDomains on the next write
59
59
  helpCenterDomain?: ISaasHelpCenterDomain;
60
60
  helpCenterDomains?: ISaasHelpCenterDomain[];
61
+ // 'new' for dashboard.erxes.io organizations; missing or 'old' otherwise
62
+ gpStatus?: string;
63
+ gpStripeCustomerId?: string;
61
64
  }
62
65
 
63
66
  export interface ISaasBundle {
@@ -1,6 +1,10 @@
1
1
  import * as dotenv from 'dotenv';
2
2
  import { redis } from './redis';
3
- import { getSaasOrganizationDetail } from './saas';
3
+ import {
4
+ getGlobalProfileV2Plugins,
5
+ getSaasOrganizationDetail,
6
+ isGlobalProfileV2,
7
+ } from './saas';
4
8
  import { getEnv } from './utils';
5
9
  import { IOrganizationCharge } from '../core-types';
6
10
  import { sendWorkerQueue } from './mq-worker';
@@ -62,6 +66,16 @@ export const getAvailablePlugins = async (
62
66
  subdomain,
63
67
  });
64
68
 
69
+ if (isGlobalProfileV2(organizationInfo)) {
70
+ const enabled = [
71
+ ...ENABLED_PLUGINS.split(','),
72
+ ...ENABLED_API_PLUGINS.split(','),
73
+ ];
74
+ const plugins = await getGlobalProfileV2Plugins(organizationInfo);
75
+
76
+ return ['core', ...plugins.filter((plugin) => enabled.includes(plugin))];
77
+ }
78
+
65
79
  const charges = organizationInfo.charge as IOrganizationCharge;
66
80
 
67
81
  const plugins: string[] = [];
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var startPlugin = require('../../dist/start-plugin-89fa2bd2.cjs.dev.js');
5
+ var startPlugin = require('../../dist/start-plugin-7dc096bc.cjs.dev.js');
6
6
  var mongoose = require('mongoose');
7
7
  var stream$1 = require('stream');
8
8
  var _loadash = require('lodash');
@@ -2806,6 +2806,7 @@ exports.AGENT_TOOL_DEFAULT_MAX_RESPONSE_BYTES = startPlugin.AGENT_TOOL_DEFAULT_M
2806
2806
  exports.DEFAULT_JOB_OPTIONS = startPlugin.DEFAULT_JOB_OPTIONS;
2807
2807
  exports.EXPECTED_ERROR_NAME = startPlugin.EXPECTED_ERROR_NAME;
2808
2808
  exports.ExpectedError = startPlugin.ExpectedError;
2809
+ exports.GP_STATUS = startPlugin.GP_STATUS;
2809
2810
  exports.HEADER_SIZE_WARN_BYTES = startPlugin.HEADER_SIZE_WARN_BYTES;
2810
2811
  exports.MAX_HEADER_BYTES = startPlugin.MAX_HEADER_BYTES;
2811
2812
  exports.ORGANIZATION_ID_MAPPING = startPlugin.ORGANIZATION_ID_MAPPING;
@@ -2910,6 +2911,7 @@ exports.getDate = startPlugin.getDate;
2910
2911
  exports.getDiffObjects = startPlugin.getDiffObjects;
2911
2912
  exports.getEnv = startPlugin.getEnv;
2912
2913
  exports.getFullDate = startPlugin.getFullDate;
2914
+ exports.getGlobalProfileV2Plugins = startPlugin.getGlobalProfileV2Plugins;
2913
2915
  exports.getNextMonth = startPlugin.getNextMonth;
2914
2916
  exports.getPlugin = startPlugin.getPlugin;
2915
2917
  exports.getPluginAddress = startPlugin.getPluginAddress;
@@ -2943,6 +2945,7 @@ exports.initializePluginConfig = startPlugin.initializePluginConfig;
2943
2945
  exports.isDev = startPlugin.isDev;
2944
2946
  exports.isEnabled = startPlugin.isEnabled;
2945
2947
  exports.isExpectedError = startPlugin.isExpectedError;
2948
+ exports.isGlobalProfileV2 = startPlugin.isGlobalProfileV2;
2946
2949
  exports.isImage = startPlugin.isImage;
2947
2950
  exports.isValidURL = startPlugin.isValidURL;
2948
2951
  exports.isVideo = startPlugin.isVideo;
@@ -2961,6 +2964,8 @@ exports.mountAgentTools = startPlugin.mountAgentTools;
2961
2964
  exports.ok = startPlugin.ok;
2962
2965
  exports.oversizedAgentToolResultBytes = startPlugin.oversizedAgentToolResultBytes;
2963
2966
  exports.paginate = startPlugin.paginate;
2967
+ exports.pluginsFromStripe = startPlugin.pluginsFromStripe;
2968
+ exports.pluginsOfStripeItem = startPlugin.pluginsOfStripeItem;
2964
2969
  exports.pluralFormation = startPlugin.pluralFormation;
2965
2970
  exports.random = startPlugin.random;
2966
2971
  exports.randomAlphanumeric = startPlugin.randomAlphanumeric;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var startPlugin = require('../../dist/start-plugin-576e707d.cjs.prod.js');
5
+ var startPlugin = require('../../dist/start-plugin-b095acca.cjs.prod.js');
6
6
  var mongoose = require('mongoose');
7
7
  var stream$1 = require('stream');
8
8
  var _loadash = require('lodash');
@@ -2806,6 +2806,7 @@ exports.AGENT_TOOL_DEFAULT_MAX_RESPONSE_BYTES = startPlugin.AGENT_TOOL_DEFAULT_M
2806
2806
  exports.DEFAULT_JOB_OPTIONS = startPlugin.DEFAULT_JOB_OPTIONS;
2807
2807
  exports.EXPECTED_ERROR_NAME = startPlugin.EXPECTED_ERROR_NAME;
2808
2808
  exports.ExpectedError = startPlugin.ExpectedError;
2809
+ exports.GP_STATUS = startPlugin.GP_STATUS;
2809
2810
  exports.HEADER_SIZE_WARN_BYTES = startPlugin.HEADER_SIZE_WARN_BYTES;
2810
2811
  exports.MAX_HEADER_BYTES = startPlugin.MAX_HEADER_BYTES;
2811
2812
  exports.ORGANIZATION_ID_MAPPING = startPlugin.ORGANIZATION_ID_MAPPING;
@@ -2910,6 +2911,7 @@ exports.getDate = startPlugin.getDate;
2910
2911
  exports.getDiffObjects = startPlugin.getDiffObjects;
2911
2912
  exports.getEnv = startPlugin.getEnv;
2912
2913
  exports.getFullDate = startPlugin.getFullDate;
2914
+ exports.getGlobalProfileV2Plugins = startPlugin.getGlobalProfileV2Plugins;
2913
2915
  exports.getNextMonth = startPlugin.getNextMonth;
2914
2916
  exports.getPlugin = startPlugin.getPlugin;
2915
2917
  exports.getPluginAddress = startPlugin.getPluginAddress;
@@ -2943,6 +2945,7 @@ exports.initializePluginConfig = startPlugin.initializePluginConfig;
2943
2945
  exports.isDev = startPlugin.isDev;
2944
2946
  exports.isEnabled = startPlugin.isEnabled;
2945
2947
  exports.isExpectedError = startPlugin.isExpectedError;
2948
+ exports.isGlobalProfileV2 = startPlugin.isGlobalProfileV2;
2946
2949
  exports.isImage = startPlugin.isImage;
2947
2950
  exports.isValidURL = startPlugin.isValidURL;
2948
2951
  exports.isVideo = startPlugin.isVideo;
@@ -2961,6 +2964,8 @@ exports.mountAgentTools = startPlugin.mountAgentTools;
2961
2964
  exports.ok = startPlugin.ok;
2962
2965
  exports.oversizedAgentToolResultBytes = startPlugin.oversizedAgentToolResultBytes;
2963
2966
  exports.paginate = startPlugin.paginate;
2967
+ exports.pluginsFromStripe = startPlugin.pluginsFromStripe;
2968
+ exports.pluginsOfStripeItem = startPlugin.pluginsOfStripeItem;
2964
2969
  exports.pluralFormation = startPlugin.pluralFormation;
2965
2970
  exports.random = startPlugin.random;
2966
2971
  exports.randomAlphanumeric = startPlugin.randomAlphanumeric;
@@ -1,5 +1,5 @@
1
- import { u as userHeaderName, g as getEnv, c as connect, _ as _asyncToGenerator, a as _regeneratorRuntime, b as coreModelOrganizations, d as getSubdomain, e as getSaasCoreConnection, f as createScopedEventHandlers, h as _slicedToArray, l as logHandler, r as runBeforeResolvers, s as sendWorkerQueue, i as _objectSpread2, j as chunkArray, k as _createForOfIteratorHelper, m as _createClass, n as _classCallCheck, o as isValidURL, p as sendTRPCMessage, q as _inherits, t as _wrapNativeSuper, v as _callSuper, w as _defineProperty, x as _toConsumableArray } from '../../dist/start-plugin-6e76556c.esm.js';
2
- export { K as AGENT_TOOL_DEFAULT_MAX_RESPONSE_BYTES, ak as DEFAULT_JOB_OPTIONS, bY as EXPECTED_ERROR_NAME, bZ as ExpectedError, W as HEADER_SIZE_WARN_BYTES, b7 as MAX_HEADER_BYTES, aA as ORGANIZATION_ID_MAPPING, T as TBeforeResolversProducers, V as USER_HEADER_OMITTED_FIELDS, N as agentToolResponseTooLargeError, F as agentToolsAuthHeaderName, y as apolloCustomScalars, bi as applyTrustProxy, bk as authCookieOptions, I as buildAgentToolManifest, bR as buildCursorQuery, ag as buildSearchTokenFilter, D as checkBeforeResolvers, aa as checkCollectionCodeDuplication, bH as checkServiceRunning, bt as checkUserIds, j as chunkArray, b$ as classifyError, bW as cleanHtml, b0 as clearServiceDiscoveryCache, P as clientPortalHeaderName, ad as closeMongooose, X as compactUserForHeader, ah as configureSchemaSearchTokens, c as connect, bj as connectionOptions, ar as coreModelAddons, as as coreModelBundles, av as coreModelEndpoints, ay as coreModelExperiences, at as coreModelInstallations, az as coreModelOrganizationPlanHistories, b as coreModelOrganizations, ax as coreModelPlugins, aw as coreModelPromoCodes, au as coreModelUsers, Q as cpUserHeaderName, b_ as createExpectedError, bG as createHealthRoute, al as createMQWorkerWithListeners, bc as createPluginTRPCContext, bd as createTRPCContext, a8 as cursorPaginate, a9 as cursorPaginateAggregation, bC as dateToShortStr, H as decodeAgentToolsAuthHeader, bQ as decodeCursor, bb as decodeTRPCContextHeader, a7 as defaultPaginate, G as encodeAgentToolsAuthHeader, bP as encodeCursor, ba as encodeTRPCContextHeader, bf as err, bp as escapeRegExp, E as expectedErrorPlugin, S as extractCPUserFromHeader, U as extractClientPortalFromHeader, c1 as extractMessage, R as extractUserFromHeader, bs as fixDate, bB as fixNum, bK as flattenObject, z as generateApolloContext, af as generateConfiguredSearchTokens, bI as generateRequestProcess, a_ as getActivePlugins, L as getAgentToolMaxResponseBytes, a$ as getAvailablePlugins, bo as getCoreDomain, bv as getDate, bJ as getDiffObjects, g as getEnv, bx as getFullDate, bA as getNextMonth, b1 as getPlugin, b5 as getPluginAddress, aY as getPlugins, by as getPureDate, e as getSaasCoreConnection, aT as getSaasOrgPromoCodes, aO as getSaasOrganizationActiveAddons, aH as getSaasOrganizationByHelpCenterDomain, aM as getSaasOrganizationDetail, aI as getSaasOrganizationHelpCenterDomains, aB as getSaasOrganizationIdBySubdomain, aN as getSaasOrganizationPlanHistories, aD as getSaasOrganizations, aE as getSaasOrganizationsByFilter, aJ as getSaasOrganizationsWithPendingHelpCenterDomain, aC as getSaasOrgsCache, aR as getSaasPlugin, aQ as getSaasPlugins, aS as getSaasPromoCodes, ai as getSchemaSearchTokenConfig, d as getSubdomain, bw as getToday, bz as getTomorrow, bh as getTrustProxySetting, bu as getUniqueValue, O as graphqlPubsub, aG as helpCenterDomainsOf, c3 as initErxesSentry, b6 as initializePluginConfig, aW as isDev, b4 as isEnabled, c0 as isExpectedError, bE as isImage, o as isValidURL, bF as isVideo, b2 as joinErxesGateway, aX as keyForConfig, b3 as leaveErxesGateway, l as logHandler, B as markResolvers, a3 as mongoStringRequired, ac as mongooseConnectionOptions, a5 as mongooseField, a2 as mongooseStringNonBlank, a1 as mongooseStringRandomId, a4 as mongooseStringRequiredNonBlank, J as mountAgentTools, be as ok, M as oversizedAgentToolResultBytes, bl as paginate, br as pluralFormation, bX as random, an as randomAlphanumeric, ao as randomLowercase, bM as readFileFromStorage, bN as readFileStreamFromStorage, bL as readFileUrl, ap as redis, bn as regexSearchText, bU as removeExtraSpaces, bT as removeLastTrailingSlash, aP as removeOrgsCache, aL as removeSaasOrganizationHelpCenterDomain, aq as resetConfigsCache, r as runBeforeResolvers, aU as sanitizeFilename, aV as sanitizeKey, aK as saveSaasOrganizationHelpCenterDomain, ab as schemaWrapper, bg as sendCoreModuleProducer, p as sendTRPCMessage, am as sendWorkerMessage, s as sendWorkerQueue, c2 as sentryExpectedErrorFilter, aZ as setActivePlugins, Z as setCPUserHeader, $ as setClientPortalHeader, Y as setUserHeader, bD as shortStrToDate, ae as splitSearchWords, bV as splitStr, a0 as startAfterProcess, C as startBeforeResolvers, b8 as startPlugin, bS as stripAnsi, aj as toSerializablePayload, b9 as trpcContextHeaderName, a6 as updateMongoDocumentOrder, bq as updateOrder, aF as updateSaasOrganization, bO as uploadFileToStorage, u as userHeaderName, bm as validSearchText, A as wrapApolloResolvers } from '../../dist/start-plugin-6e76556c.esm.js';
1
+ import { u as userHeaderName, g as getEnv, c as connect, _ as _asyncToGenerator, a as _regeneratorRuntime, b as coreModelOrganizations, d as getSubdomain, e as getSaasCoreConnection, f as createScopedEventHandlers, h as _slicedToArray, l as logHandler, r as runBeforeResolvers, s as sendWorkerQueue, i as _objectSpread2, j as chunkArray, k as _createForOfIteratorHelper, m as _createClass, n as _classCallCheck, o as isValidURL, p as sendTRPCMessage, q as _inherits, t as _wrapNativeSuper, v as _callSuper, w as _defineProperty, x as _toConsumableArray } from '../../dist/start-plugin-a2f6eca9.esm.js';
2
+ export { K as AGENT_TOOL_DEFAULT_MAX_RESPONSE_BYTES, ak as DEFAULT_JOB_OPTIONS, c1 as EXPECTED_ERROR_NAME, c2 as ExpectedError, aU as GP_STATUS, W as HEADER_SIZE_WARN_BYTES, bc as MAX_HEADER_BYTES, aA as ORGANIZATION_ID_MAPPING, T as TBeforeResolversProducers, V as USER_HEADER_OMITTED_FIELDS, N as agentToolResponseTooLargeError, F as agentToolsAuthHeaderName, y as apolloCustomScalars, bn as applyTrustProxy, bp as authCookieOptions, I as buildAgentToolManifest, bW as buildCursorQuery, ag as buildSearchTokenFilter, D as checkBeforeResolvers, aa as checkCollectionCodeDuplication, bM as checkServiceRunning, by as checkUserIds, j as chunkArray, c4 as classifyError, b$ as cleanHtml, b5 as clearServiceDiscoveryCache, P as clientPortalHeaderName, ad as closeMongooose, X as compactUserForHeader, ah as configureSchemaSearchTokens, c as connect, bo as connectionOptions, ar as coreModelAddons, as as coreModelBundles, av as coreModelEndpoints, ay as coreModelExperiences, at as coreModelInstallations, az as coreModelOrganizationPlanHistories, b as coreModelOrganizations, ax as coreModelPlugins, aw as coreModelPromoCodes, au as coreModelUsers, Q as cpUserHeaderName, c3 as createExpectedError, bL as createHealthRoute, al as createMQWorkerWithListeners, bh as createPluginTRPCContext, bi as createTRPCContext, a8 as cursorPaginate, a9 as cursorPaginateAggregation, bH as dateToShortStr, H as decodeAgentToolsAuthHeader, bV as decodeCursor, bg as decodeTRPCContextHeader, a7 as defaultPaginate, G as encodeAgentToolsAuthHeader, bU as encodeCursor, bf as encodeTRPCContextHeader, bk as err, bu as escapeRegExp, E as expectedErrorPlugin, S as extractCPUserFromHeader, U as extractClientPortalFromHeader, c6 as extractMessage, R as extractUserFromHeader, bx as fixDate, bG as fixNum, bP as flattenObject, z as generateApolloContext, af as generateConfiguredSearchTokens, bN as generateRequestProcess, b3 as getActivePlugins, L as getAgentToolMaxResponseBytes, b4 as getAvailablePlugins, bt as getCoreDomain, bA as getDate, bO as getDiffObjects, g as getEnv, bC as getFullDate, aY as getGlobalProfileV2Plugins, bF as getNextMonth, b6 as getPlugin, ba as getPluginAddress, b1 as getPlugins, bD as getPureDate, e as getSaasCoreConnection, aT as getSaasOrgPromoCodes, aO as getSaasOrganizationActiveAddons, aH as getSaasOrganizationByHelpCenterDomain, aM as getSaasOrganizationDetail, aI as getSaasOrganizationHelpCenterDomains, aB as getSaasOrganizationIdBySubdomain, aN as getSaasOrganizationPlanHistories, aD as getSaasOrganizations, aE as getSaasOrganizationsByFilter, aJ as getSaasOrganizationsWithPendingHelpCenterDomain, aC as getSaasOrgsCache, aR as getSaasPlugin, aQ as getSaasPlugins, aS as getSaasPromoCodes, ai as getSchemaSearchTokenConfig, d as getSubdomain, bB as getToday, bE as getTomorrow, bm as getTrustProxySetting, bz as getUniqueValue, O as graphqlPubsub, aG as helpCenterDomainsOf, c8 as initErxesSentry, bb as initializePluginConfig, a$ as isDev, b9 as isEnabled, c5 as isExpectedError, aV as isGlobalProfileV2, bJ as isImage, o as isValidURL, bK as isVideo, b7 as joinErxesGateway, b0 as keyForConfig, b8 as leaveErxesGateway, l as logHandler, B as markResolvers, a3 as mongoStringRequired, ac as mongooseConnectionOptions, a5 as mongooseField, a2 as mongooseStringNonBlank, a1 as mongooseStringRandomId, a4 as mongooseStringRequiredNonBlank, J as mountAgentTools, bj as ok, M as oversizedAgentToolResultBytes, bq as paginate, aX as pluginsFromStripe, aW as pluginsOfStripeItem, bw as pluralFormation, c0 as random, an as randomAlphanumeric, ao as randomLowercase, bR as readFileFromStorage, bS as readFileStreamFromStorage, bQ as readFileUrl, ap as redis, bs as regexSearchText, bZ as removeExtraSpaces, bY as removeLastTrailingSlash, aP as removeOrgsCache, aL as removeSaasOrganizationHelpCenterDomain, aq as resetConfigsCache, r as runBeforeResolvers, aZ as sanitizeFilename, a_ as sanitizeKey, aK as saveSaasOrganizationHelpCenterDomain, ab as schemaWrapper, bl as sendCoreModuleProducer, p as sendTRPCMessage, am as sendWorkerMessage, s as sendWorkerQueue, c7 as sentryExpectedErrorFilter, b2 as setActivePlugins, Z as setCPUserHeader, $ as setClientPortalHeader, Y as setUserHeader, bI as shortStrToDate, ae as splitSearchWords, b_ as splitStr, a0 as startAfterProcess, C as startBeforeResolvers, bd as startPlugin, bX as stripAnsi, aj as toSerializablePayload, be as trpcContextHeaderName, a6 as updateMongoDocumentOrder, bv as updateOrder, aF as updateSaasOrganization, bT as uploadFileToStorage, u as userHeaderName, br as validSearchText, A as wrapApolloResolvers } from '../../dist/start-plugin-a2f6eca9.esm.js';
3
3
  import mongoose from 'mongoose';
4
4
  import { Transform } from 'stream';
5
5
  import { keyBy } from 'lodash';