@budibase/backend-core 2.31.2 → 2.31.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +259 -237
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/db/couch/DatabaseImpl.js +3 -2
- package/dist/src/db/couch/DatabaseImpl.js.map +1 -1
- package/dist/src/db/utils.d.ts +0 -1
- package/dist/src/db/utils.js +0 -23
- package/dist/src/db/utils.js.map +1 -1
- package/dist/src/docIds/params.d.ts +1 -1
- package/dist/src/docIds/params.js +1 -1
- package/dist/src/docIds/params.js.map +1 -1
- package/dist/src/environment.d.ts +0 -3
- package/dist/src/environment.js +1 -2
- package/dist/src/environment.js.map +1 -1
- package/dist/src/features/index.d.ts +2 -0
- package/dist/src/features/index.js +4 -2
- package/dist/src/features/index.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/tenancy/db.d.ts +1 -1
- package/dist/src/tenancy/db.js +9 -2
- package/dist/src/tenancy/db.js.map +1 -1
- package/package.json +4 -4
- package/src/db/couch/DatabaseImpl.ts +5 -2
- package/src/db/tests/index.spec.ts +32 -0
- package/src/db/utils.ts +1 -32
- package/src/docIds/params.ts +1 -1
- package/src/environment.ts +0 -4
- package/src/features/index.ts +5 -3
- package/src/features/tests/features.spec.ts +1 -1
- package/src/tenancy/db.ts +11 -3
- package/src/db/tests/index.spec.js +0 -24
package/dist/index.js
CHANGED
|
@@ -54870,6 +54870,7 @@ __export(filters_exports, {
|
|
|
54870
54870
|
hasFilters: () => hasFilters,
|
|
54871
54871
|
limit: () => limit,
|
|
54872
54872
|
recurseLogicalOperators: () => recurseLogicalOperators,
|
|
54873
|
+
recurseSearchFilters: () => recurseSearchFilters,
|
|
54873
54874
|
removeKeyNumbering: () => removeKeyNumbering,
|
|
54874
54875
|
runQuery: () => runQuery,
|
|
54875
54876
|
search: () => search,
|
|
@@ -54880,6 +54881,7 @@ var import_dayjs = __toESM(require_dayjs_min());
|
|
|
54880
54881
|
// ../shared-core/src/helpers/index.ts
|
|
54881
54882
|
var helpers_exports = {};
|
|
54882
54883
|
__export(helpers_exports, {
|
|
54884
|
+
cancelableTimeout: () => cancelableTimeout,
|
|
54883
54885
|
cron: () => cron_exports,
|
|
54884
54886
|
deepGet: () => deepGet,
|
|
54885
54887
|
getUserColor: () => getUserColor,
|
|
@@ -54887,7 +54889,8 @@ __export(helpers_exports, {
|
|
|
54887
54889
|
getUserLabel: () => getUserLabel,
|
|
54888
54890
|
isGoogleSheets: () => isGoogleSheets,
|
|
54889
54891
|
isSQL: () => isSQL,
|
|
54890
|
-
schema: () => schema_exports
|
|
54892
|
+
schema: () => schema_exports,
|
|
54893
|
+
withTimeout: () => withTimeout
|
|
54891
54894
|
});
|
|
54892
54895
|
|
|
54893
54896
|
// ../shared-core/src/helpers/helpers.ts
|
|
@@ -54944,6 +54947,28 @@ var getUserLabel = (user) => {
|
|
|
54944
54947
|
return email;
|
|
54945
54948
|
}
|
|
54946
54949
|
};
|
|
54950
|
+
function cancelableTimeout(timeout2) {
|
|
54951
|
+
let timeoutId;
|
|
54952
|
+
return [
|
|
54953
|
+
new Promise((resolve, reject) => {
|
|
54954
|
+
timeoutId = setTimeout(() => {
|
|
54955
|
+
reject({
|
|
54956
|
+
status: 301,
|
|
54957
|
+
errno: "ETIME"
|
|
54958
|
+
});
|
|
54959
|
+
}, timeout2);
|
|
54960
|
+
}),
|
|
54961
|
+
() => {
|
|
54962
|
+
clearTimeout(timeoutId);
|
|
54963
|
+
}
|
|
54964
|
+
];
|
|
54965
|
+
}
|
|
54966
|
+
async function withTimeout(timeout2, promise) {
|
|
54967
|
+
const [timeoutPromise, cancel] = cancelableTimeout(timeout2);
|
|
54968
|
+
const result = await Promise.race([promise, timeoutPromise]);
|
|
54969
|
+
cancel();
|
|
54970
|
+
return result;
|
|
54971
|
+
}
|
|
54947
54972
|
|
|
54948
54973
|
// ../shared-core/src/helpers/integrations.ts
|
|
54949
54974
|
function isGoogleSheets(type) {
|
|
@@ -55109,6 +55134,17 @@ function recurseLogicalOperators(filters, fn) {
|
|
|
55109
55134
|
}
|
|
55110
55135
|
return filters;
|
|
55111
55136
|
}
|
|
55137
|
+
function recurseSearchFilters(filters, processFn) {
|
|
55138
|
+
filters = processFn(filters);
|
|
55139
|
+
for (const logical of Object.values(LogicalOperator)) {
|
|
55140
|
+
if (filters[logical]) {
|
|
55141
|
+
filters[logical].conditions = filters[logical].conditions.map(
|
|
55142
|
+
(condition) => recurseSearchFilters(condition, processFn)
|
|
55143
|
+
);
|
|
55144
|
+
}
|
|
55145
|
+
}
|
|
55146
|
+
return filters;
|
|
55147
|
+
}
|
|
55112
55148
|
var cleanupQuery = (query) => {
|
|
55113
55149
|
if (!query) {
|
|
55114
55150
|
return query;
|
|
@@ -56212,9 +56248,6 @@ var environment = {
|
|
|
56212
56248
|
API_ENCRYPTION_KEY: getAPIEncryptionKey(),
|
|
56213
56249
|
COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
|
|
56214
56250
|
COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL,
|
|
56215
|
-
SQS_SEARCH_ENABLE: process.env.SQS_SEARCH_ENABLE,
|
|
56216
|
-
SQS_SEARCH_ENABLE_TENANTS: process.env.SQS_SEARCH_ENABLE_TENANTS?.split(",") || [],
|
|
56217
|
-
SQS_MIGRATION_ENABLE: process.env.SQS_MIGRATION_ENABLE,
|
|
56218
56251
|
COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
|
|
56219
56252
|
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
|
|
56220
56253
|
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
|
@@ -56847,7 +56880,6 @@ __export(db_exports, {
|
|
|
56847
56880
|
isGlobalUserID: () => isGlobalUserID,
|
|
56848
56881
|
isProdAppID: () => isProdAppID,
|
|
56849
56882
|
isSameAppID: () => isSameAppID,
|
|
56850
|
-
isSqsEnabledForTenant: () => isSqsEnabledForTenant,
|
|
56851
56883
|
isTableId: () => isTableId,
|
|
56852
56884
|
paginatedSearch: () => paginatedSearch,
|
|
56853
56885
|
pagination: () => pagination,
|
|
@@ -58549,7 +58581,7 @@ function getQueryIndex(viewName) {
|
|
|
58549
58581
|
return `database/${viewName}`;
|
|
58550
58582
|
}
|
|
58551
58583
|
var isTableId = (id) => {
|
|
58552
|
-
return id && (id.startsWith(`${"ta" /* TABLE */}${SEPARATOR}`) || id.startsWith(`${"datasource_plus" /* DATASOURCE_PLUS */}${SEPARATOR}`));
|
|
58584
|
+
return !!id && (id.startsWith(`${"ta" /* TABLE */}${SEPARATOR}`) || id.startsWith(`${"datasource_plus" /* DATASOURCE_PLUS */}${SEPARATOR}`));
|
|
58553
58585
|
};
|
|
58554
58586
|
var isDatasourceId = (id) => {
|
|
58555
58587
|
return id && id.startsWith(`${"datasource" /* DATASOURCE */}${SEPARATOR}`);
|
|
@@ -58748,24 +58780,6 @@ function pagination(data, pageSize, {
|
|
|
58748
58780
|
nextPage
|
|
58749
58781
|
};
|
|
58750
58782
|
}
|
|
58751
|
-
function isSqsEnabledForTenant() {
|
|
58752
|
-
const tenantId = getTenantId();
|
|
58753
|
-
if (!environment_default.SQS_SEARCH_ENABLE) {
|
|
58754
|
-
return false;
|
|
58755
|
-
}
|
|
58756
|
-
if (!isMultiTenant()) {
|
|
58757
|
-
return true;
|
|
58758
|
-
}
|
|
58759
|
-
if (environment_default.isTest() && environment_default.SQS_SEARCH_ENABLE_TENANTS.length === 0) {
|
|
58760
|
-
throw new Error(
|
|
58761
|
-
"to enable SQS you must specify a list of tenants in the SQS_SEARCH_ENABLE_TENANTS env var"
|
|
58762
|
-
);
|
|
58763
|
-
}
|
|
58764
|
-
if (environment_default.SQS_SEARCH_ENABLE_TENANTS.length === 1 && environment_default.SQS_SEARCH_ENABLE_TENANTS[0] === "*") {
|
|
58765
|
-
return true;
|
|
58766
|
-
}
|
|
58767
|
-
return environment_default.SQS_SEARCH_ENABLE_TENANTS.includes(tenantId);
|
|
58768
|
-
}
|
|
58769
58783
|
|
|
58770
58784
|
// src/db/views.ts
|
|
58771
58785
|
var DESIGN_DB = "_design/database";
|
|
@@ -59749,6 +59763,200 @@ function sqlLog(client, query, values2) {
|
|
|
59749
59763
|
console.log(string);
|
|
59750
59764
|
}
|
|
59751
59765
|
|
|
59766
|
+
// src/features/index.ts
|
|
59767
|
+
var features_exports = {};
|
|
59768
|
+
__export(features_exports, {
|
|
59769
|
+
Flag: () => Flag,
|
|
59770
|
+
FlagSet: () => FlagSet,
|
|
59771
|
+
flags: () => flags,
|
|
59772
|
+
init: () => init4,
|
|
59773
|
+
shutdown: () => shutdown2
|
|
59774
|
+
});
|
|
59775
|
+
var import_posthog_node = require("posthog-node");
|
|
59776
|
+
var import_dd_trace3 = __toESM(require("dd-trace"));
|
|
59777
|
+
var posthog;
|
|
59778
|
+
function init4(opts) {
|
|
59779
|
+
if (environment_default.POSTHOG_TOKEN && environment_default.POSTHOG_API_HOST && !environment_default.SELF_HOSTED) {
|
|
59780
|
+
console.log("initializing posthog client...");
|
|
59781
|
+
posthog = new import_posthog_node.PostHog(environment_default.POSTHOG_TOKEN, {
|
|
59782
|
+
host: environment_default.POSTHOG_API_HOST,
|
|
59783
|
+
personalApiKey: environment_default.POSTHOG_PERSONAL_TOKEN,
|
|
59784
|
+
...opts
|
|
59785
|
+
});
|
|
59786
|
+
} else {
|
|
59787
|
+
console.log("posthog disabled");
|
|
59788
|
+
}
|
|
59789
|
+
}
|
|
59790
|
+
function shutdown2() {
|
|
59791
|
+
posthog?.shutdown();
|
|
59792
|
+
}
|
|
59793
|
+
var Flag = class {
|
|
59794
|
+
constructor(defaultValue) {
|
|
59795
|
+
this.defaultValue = defaultValue;
|
|
59796
|
+
}
|
|
59797
|
+
static boolean(defaultValue) {
|
|
59798
|
+
return new BooleanFlag(defaultValue);
|
|
59799
|
+
}
|
|
59800
|
+
static string(defaultValue) {
|
|
59801
|
+
return new StringFlag(defaultValue);
|
|
59802
|
+
}
|
|
59803
|
+
static number(defaultValue) {
|
|
59804
|
+
return new NumberFlag(defaultValue);
|
|
59805
|
+
}
|
|
59806
|
+
};
|
|
59807
|
+
var BooleanFlag = class extends Flag {
|
|
59808
|
+
parse(value) {
|
|
59809
|
+
if (typeof value === "string") {
|
|
59810
|
+
return ["true", "t", "1"].includes(value.toLowerCase());
|
|
59811
|
+
}
|
|
59812
|
+
if (typeof value === "boolean") {
|
|
59813
|
+
return value;
|
|
59814
|
+
}
|
|
59815
|
+
throw new Error(`could not parse value "${value}" as boolean`);
|
|
59816
|
+
}
|
|
59817
|
+
};
|
|
59818
|
+
var StringFlag = class extends Flag {
|
|
59819
|
+
parse(value) {
|
|
59820
|
+
if (typeof value === "string") {
|
|
59821
|
+
return value;
|
|
59822
|
+
}
|
|
59823
|
+
throw new Error(`could not parse value "${value}" as string`);
|
|
59824
|
+
}
|
|
59825
|
+
};
|
|
59826
|
+
var NumberFlag = class extends Flag {
|
|
59827
|
+
parse(value) {
|
|
59828
|
+
if (typeof value === "number") {
|
|
59829
|
+
return value;
|
|
59830
|
+
}
|
|
59831
|
+
if (typeof value === "string") {
|
|
59832
|
+
const parsed = parseFloat(value);
|
|
59833
|
+
if (!isNaN(parsed)) {
|
|
59834
|
+
return parsed;
|
|
59835
|
+
}
|
|
59836
|
+
}
|
|
59837
|
+
throw new Error(`could not parse value "${value}" as number`);
|
|
59838
|
+
}
|
|
59839
|
+
};
|
|
59840
|
+
var FlagSet = class {
|
|
59841
|
+
constructor(flagSchema) {
|
|
59842
|
+
this.flagSchema = flagSchema;
|
|
59843
|
+
this.setId = crypto.randomUUID();
|
|
59844
|
+
}
|
|
59845
|
+
defaults() {
|
|
59846
|
+
return Object.keys(this.flagSchema).reduce((acc, key) => {
|
|
59847
|
+
const typedKey = key;
|
|
59848
|
+
acc[typedKey] = this.flagSchema[key].defaultValue;
|
|
59849
|
+
return acc;
|
|
59850
|
+
}, {});
|
|
59851
|
+
}
|
|
59852
|
+
isFlagName(name) {
|
|
59853
|
+
return this.flagSchema[name] !== void 0;
|
|
59854
|
+
}
|
|
59855
|
+
async get(key, ctx) {
|
|
59856
|
+
const flags2 = await this.fetch(ctx);
|
|
59857
|
+
return flags2[key];
|
|
59858
|
+
}
|
|
59859
|
+
async isEnabled(key, ctx) {
|
|
59860
|
+
const flags2 = await this.fetch(ctx);
|
|
59861
|
+
return flags2[key];
|
|
59862
|
+
}
|
|
59863
|
+
async fetch(ctx) {
|
|
59864
|
+
return await import_dd_trace3.default.trace("features.fetch", async (span) => {
|
|
59865
|
+
const cachedFlags = getFeatureFlags(this.setId);
|
|
59866
|
+
if (cachedFlags) {
|
|
59867
|
+
span?.addTags({ fromCache: true });
|
|
59868
|
+
return cachedFlags;
|
|
59869
|
+
}
|
|
59870
|
+
const tags = {};
|
|
59871
|
+
const flagValues = this.defaults();
|
|
59872
|
+
const currentTenantId = getTenantId();
|
|
59873
|
+
const specificallySetFalse = /* @__PURE__ */ new Set();
|
|
59874
|
+
const split = (environment_default.TENANT_FEATURE_FLAGS || "").split(",").map((x) => x.split(":"));
|
|
59875
|
+
for (const [tenantId, ...features] of split) {
|
|
59876
|
+
if (!tenantId || tenantId !== "*" && tenantId !== currentTenantId) {
|
|
59877
|
+
continue;
|
|
59878
|
+
}
|
|
59879
|
+
tags[`readFromEnvironmentVars`] = true;
|
|
59880
|
+
for (let feature of features) {
|
|
59881
|
+
let value = true;
|
|
59882
|
+
if (feature.startsWith("!")) {
|
|
59883
|
+
feature = feature.slice(1);
|
|
59884
|
+
value = false;
|
|
59885
|
+
specificallySetFalse.add(feature);
|
|
59886
|
+
}
|
|
59887
|
+
if (!this.isFlagName(feature)) {
|
|
59888
|
+
continue;
|
|
59889
|
+
}
|
|
59890
|
+
if (typeof flagValues[feature] !== "boolean") {
|
|
59891
|
+
throw new Error(`Feature: ${feature} is not a boolean`);
|
|
59892
|
+
}
|
|
59893
|
+
flagValues[feature] = value;
|
|
59894
|
+
tags[`flags.${feature}.source`] = "environment";
|
|
59895
|
+
}
|
|
59896
|
+
}
|
|
59897
|
+
const license = ctx?.user?.license;
|
|
59898
|
+
if (license) {
|
|
59899
|
+
tags[`readFromLicense`] = true;
|
|
59900
|
+
for (const feature of license.features) {
|
|
59901
|
+
if (!this.isFlagName(feature)) {
|
|
59902
|
+
continue;
|
|
59903
|
+
}
|
|
59904
|
+
if (flagValues[feature] === true || specificallySetFalse.has(feature)) {
|
|
59905
|
+
continue;
|
|
59906
|
+
}
|
|
59907
|
+
flagValues[feature] = true;
|
|
59908
|
+
tags[`flags.${feature}.source`] = "license";
|
|
59909
|
+
}
|
|
59910
|
+
}
|
|
59911
|
+
const identity = getIdentity();
|
|
59912
|
+
tags[`identity.type`] = identity?.type;
|
|
59913
|
+
tags[`identity.tenantId`] = identity?.tenantId;
|
|
59914
|
+
tags[`identity._id`] = identity?._id;
|
|
59915
|
+
if (posthog && identity?.type === "user" /* USER */) {
|
|
59916
|
+
tags[`readFromPostHog`] = true;
|
|
59917
|
+
const personProperties = {};
|
|
59918
|
+
if (identity.tenantId) {
|
|
59919
|
+
personProperties.tenantId = identity.tenantId;
|
|
59920
|
+
}
|
|
59921
|
+
const posthogFlags = await posthog.getAllFlagsAndPayloads(
|
|
59922
|
+
identity._id,
|
|
59923
|
+
{
|
|
59924
|
+
personProperties
|
|
59925
|
+
}
|
|
59926
|
+
);
|
|
59927
|
+
for (const [name, value] of Object.entries(posthogFlags.featureFlags)) {
|
|
59928
|
+
if (!this.isFlagName(name)) {
|
|
59929
|
+
console.warn(`Unexpected posthog flag "${name}": ${value}`);
|
|
59930
|
+
continue;
|
|
59931
|
+
}
|
|
59932
|
+
if (flagValues[name] === true || specificallySetFalse.has(name)) {
|
|
59933
|
+
continue;
|
|
59934
|
+
}
|
|
59935
|
+
const payload = posthogFlags.featureFlagPayloads?.[name];
|
|
59936
|
+
const flag = this.flagSchema[name];
|
|
59937
|
+
try {
|
|
59938
|
+
flagValues[name] = flag.parse(payload || value);
|
|
59939
|
+
tags[`flags.${name}.source`] = "posthog";
|
|
59940
|
+
} catch (err) {
|
|
59941
|
+
console.warn(`Error parsing posthog flag "${name}": ${value}`, err);
|
|
59942
|
+
}
|
|
59943
|
+
}
|
|
59944
|
+
}
|
|
59945
|
+
setFeatureFlags(this.setId, flagValues);
|
|
59946
|
+
for (const [key, value] of Object.entries(flagValues)) {
|
|
59947
|
+
tags[`flags.${key}.value`] = value;
|
|
59948
|
+
}
|
|
59949
|
+
span?.addTags(tags);
|
|
59950
|
+
return flagValues;
|
|
59951
|
+
});
|
|
59952
|
+
}
|
|
59953
|
+
};
|
|
59954
|
+
var flags = new FlagSet({
|
|
59955
|
+
DEFAULT_VALUES: Flag.boolean(environment_default.isDev()),
|
|
59956
|
+
SQS: Flag.boolean(environment_default.isDev()),
|
|
59957
|
+
["ENRICHED_RELATIONSHIPS" /* ENRICHED_RELATIONSHIPS */]: Flag.boolean(false)
|
|
59958
|
+
});
|
|
59959
|
+
|
|
59752
59960
|
// src/db/couch/DatabaseImpl.ts
|
|
59753
59961
|
var DATABASE_NOT_FOUND = "Database does not exist.";
|
|
59754
59962
|
function buildNano(couchInfo) {
|
|
@@ -60036,7 +60244,7 @@ var DatabaseImpl = class _DatabaseImpl {
|
|
|
60036
60244
|
});
|
|
60037
60245
|
}
|
|
60038
60246
|
async destroy() {
|
|
60039
|
-
if (
|
|
60247
|
+
if (await flags.isEnabled("SQS") && await this.exists(SQLITE_DESIGN_DOC_ID)) {
|
|
60040
60248
|
const definition = await this.get(SQLITE_DESIGN_DOC_ID);
|
|
60041
60249
|
definition.sql.tables = {};
|
|
60042
60250
|
await this.put(definition);
|
|
@@ -60559,8 +60767,14 @@ async function saveTenantInfo(tenantInfo) {
|
|
|
60559
60767
|
});
|
|
60560
60768
|
}
|
|
60561
60769
|
async function getTenantInfo(tenantId) {
|
|
60562
|
-
|
|
60563
|
-
|
|
60770
|
+
try {
|
|
60771
|
+
const db = getTenantDB(tenantId);
|
|
60772
|
+
const tenantInfo = await db.get("tenant_info");
|
|
60773
|
+
delete tenantInfo.owner.password;
|
|
60774
|
+
return tenantInfo;
|
|
60775
|
+
} catch {
|
|
60776
|
+
return void 0;
|
|
60777
|
+
}
|
|
60564
60778
|
}
|
|
60565
60779
|
|
|
60566
60780
|
// src/tenancy/tenancy.ts
|
|
@@ -62118,7 +62332,7 @@ __export(events_exports, {
|
|
|
62118
62332
|
rows: () => rows_default,
|
|
62119
62333
|
screen: () => screen_default,
|
|
62120
62334
|
serve: () => serve_default,
|
|
62121
|
-
shutdown: () =>
|
|
62335
|
+
shutdown: () => shutdown5,
|
|
62122
62336
|
table: () => table_default,
|
|
62123
62337
|
user: () => user_default,
|
|
62124
62338
|
view: () => view_default
|
|
@@ -62128,7 +62342,7 @@ __export(events_exports, {
|
|
|
62128
62342
|
var processors_exports = {};
|
|
62129
62343
|
__export(processors_exports, {
|
|
62130
62344
|
analyticsProcessor: () => analyticsProcessor,
|
|
62131
|
-
init: () =>
|
|
62345
|
+
init: () => init5,
|
|
62132
62346
|
processors: () => processors
|
|
62133
62347
|
});
|
|
62134
62348
|
|
|
@@ -62142,7 +62356,7 @@ var enabled = async () => {
|
|
|
62142
62356
|
};
|
|
62143
62357
|
|
|
62144
62358
|
// src/events/processors/posthog/PosthogProcessor.ts
|
|
62145
|
-
var
|
|
62359
|
+
var import_posthog_node2 = require("posthog-node");
|
|
62146
62360
|
|
|
62147
62361
|
// src/events/processors/posthog/rateLimiting.ts
|
|
62148
62362
|
var isRateLimited = (event) => {
|
|
@@ -62226,7 +62440,7 @@ var PosthogProcessor = class {
|
|
|
62226
62440
|
if (!token) {
|
|
62227
62441
|
throw new Error("Posthog token is not defined");
|
|
62228
62442
|
}
|
|
62229
|
-
this.posthog = new
|
|
62443
|
+
this.posthog = new import_posthog_node2.PostHog(token);
|
|
62230
62444
|
}
|
|
62231
62445
|
async processEvent(event, identity, properties, timestamp) {
|
|
62232
62446
|
if (EXCLUDED_EVENTS.includes(event)) {
|
|
@@ -62370,7 +62584,7 @@ __export(queue_exports, {
|
|
|
62370
62584
|
Queue: () => import_bull2.Queue,
|
|
62371
62585
|
QueueOptions: () => import_bull2.QueueOptions,
|
|
62372
62586
|
createQueue: () => createQueue,
|
|
62373
|
-
shutdown: () =>
|
|
62587
|
+
shutdown: () => shutdown3
|
|
62374
62588
|
});
|
|
62375
62589
|
|
|
62376
62590
|
// src/queue/inMemoryQueue.ts
|
|
@@ -62693,7 +62907,7 @@ function createQueue(jobQueue, opts = {}) {
|
|
|
62693
62907
|
}
|
|
62694
62908
|
return queue;
|
|
62695
62909
|
}
|
|
62696
|
-
async function
|
|
62910
|
+
async function shutdown3() {
|
|
62697
62911
|
if (cleanupInterval) {
|
|
62698
62912
|
clear(cleanupInterval);
|
|
62699
62913
|
}
|
|
@@ -62805,7 +63019,7 @@ var Processor = class {
|
|
|
62805
63019
|
var analyticsProcessor = new AnalyticsProcessor();
|
|
62806
63020
|
var loggingProcessor = new LoggingProcessor();
|
|
62807
63021
|
var auditLogsProcessor = new AuditLogsProcessor();
|
|
62808
|
-
function
|
|
63022
|
+
function init5(auditingFn) {
|
|
62809
63023
|
return AuditLogsProcessor.init(auditingFn);
|
|
62810
63024
|
}
|
|
62811
63025
|
var processors = new Processor([
|
|
@@ -63281,10 +63495,10 @@ var getEventKey = (event, properties) => {
|
|
|
63281
63495
|
|
|
63282
63496
|
// src/events/asyncEvents/queue.ts
|
|
63283
63497
|
var asyncEventQueue;
|
|
63284
|
-
function
|
|
63498
|
+
function init6() {
|
|
63285
63499
|
asyncEventQueue = createQueue("systemEventQueue" /* SYSTEM_EVENT_QUEUE */);
|
|
63286
63500
|
}
|
|
63287
|
-
async function
|
|
63501
|
+
async function shutdown4() {
|
|
63288
63502
|
if (asyncEventQueue) {
|
|
63289
63503
|
await asyncEventQueue.close();
|
|
63290
63504
|
}
|
|
@@ -63293,7 +63507,7 @@ async function shutdown3() {
|
|
|
63293
63507
|
// src/events/asyncEvents/publisher.ts
|
|
63294
63508
|
async function publishAsyncEvent(payload) {
|
|
63295
63509
|
if (!asyncEventQueue) {
|
|
63296
|
-
|
|
63510
|
+
init6();
|
|
63297
63511
|
}
|
|
63298
63512
|
const { event, identity } = payload;
|
|
63299
63513
|
if (AsyncEvents.indexOf(event) !== -1 && identity.tenantId) {
|
|
@@ -64426,7 +64640,7 @@ var group_default = {
|
|
|
64426
64640
|
};
|
|
64427
64641
|
|
|
64428
64642
|
// src/events/publishers/plugin.ts
|
|
64429
|
-
async function
|
|
64643
|
+
async function init7(plugin) {
|
|
64430
64644
|
const properties = {
|
|
64431
64645
|
type: plugin.schema.type,
|
|
64432
64646
|
name: plugin.name,
|
|
@@ -64457,7 +64671,7 @@ async function deleted13(plugin) {
|
|
|
64457
64671
|
await publishEvent("plugin:deleted" /* PLUGIN_DELETED */, properties);
|
|
64458
64672
|
}
|
|
64459
64673
|
var plugin_default = {
|
|
64460
|
-
init:
|
|
64674
|
+
init: init7,
|
|
64461
64675
|
imported: imported4,
|
|
64462
64676
|
deleted: deleted13
|
|
64463
64677
|
};
|
|
@@ -64537,7 +64751,7 @@ var auditLog_default = {
|
|
|
64537
64751
|
// src/events/index.ts
|
|
64538
64752
|
function initAsyncEvents() {
|
|
64539
64753
|
}
|
|
64540
|
-
var
|
|
64754
|
+
var shutdown5 = () => {
|
|
64541
64755
|
processors.shutdown();
|
|
64542
64756
|
console.log("Events shutdown");
|
|
64543
64757
|
};
|
|
@@ -65656,7 +65870,7 @@ __export(docWritethrough_exports, {
|
|
|
65656
65870
|
DocWritethrough: () => DocWritethrough,
|
|
65657
65871
|
DocWritethroughProcessor: () => DocWritethroughProcessor,
|
|
65658
65872
|
getProcessor: () => getProcessor,
|
|
65659
|
-
init: () =>
|
|
65873
|
+
init: () => init8
|
|
65660
65874
|
});
|
|
65661
65875
|
var PERSIST_MAX_ATTEMPTS = 100;
|
|
65662
65876
|
var processor;
|
|
@@ -65721,13 +65935,13 @@ var DocWritethrough = class {
|
|
|
65721
65935
|
});
|
|
65722
65936
|
}
|
|
65723
65937
|
};
|
|
65724
|
-
function
|
|
65938
|
+
function init8() {
|
|
65725
65939
|
processor = new DocWritethroughProcessor().init();
|
|
65726
65940
|
return processor;
|
|
65727
65941
|
}
|
|
65728
65942
|
function getProcessor() {
|
|
65729
65943
|
if (!processor) {
|
|
65730
|
-
return
|
|
65944
|
+
return init8();
|
|
65731
65945
|
}
|
|
65732
65946
|
return processor;
|
|
65733
65947
|
}
|
|
@@ -66058,198 +66272,6 @@ var DEFINITIONS = [
|
|
|
66058
66272
|
}
|
|
66059
66273
|
];
|
|
66060
66274
|
|
|
66061
|
-
// src/features/index.ts
|
|
66062
|
-
var features_exports = {};
|
|
66063
|
-
__export(features_exports, {
|
|
66064
|
-
Flag: () => Flag,
|
|
66065
|
-
FlagSet: () => FlagSet,
|
|
66066
|
-
flags: () => flags,
|
|
66067
|
-
init: () => init8,
|
|
66068
|
-
shutdown: () => shutdown5
|
|
66069
|
-
});
|
|
66070
|
-
var import_posthog_node2 = require("posthog-node");
|
|
66071
|
-
var import_dd_trace3 = __toESM(require("dd-trace"));
|
|
66072
|
-
var posthog;
|
|
66073
|
-
function init8(opts) {
|
|
66074
|
-
if (environment_default.POSTHOG_TOKEN && environment_default.POSTHOG_API_HOST) {
|
|
66075
|
-
console.log("initializing posthog client...");
|
|
66076
|
-
posthog = new import_posthog_node2.PostHog(environment_default.POSTHOG_TOKEN, {
|
|
66077
|
-
host: environment_default.POSTHOG_API_HOST,
|
|
66078
|
-
personalApiKey: environment_default.POSTHOG_PERSONAL_TOKEN,
|
|
66079
|
-
...opts
|
|
66080
|
-
});
|
|
66081
|
-
} else {
|
|
66082
|
-
console.log("posthog disabled");
|
|
66083
|
-
}
|
|
66084
|
-
}
|
|
66085
|
-
function shutdown5() {
|
|
66086
|
-
posthog?.shutdown();
|
|
66087
|
-
}
|
|
66088
|
-
var Flag = class {
|
|
66089
|
-
constructor(defaultValue) {
|
|
66090
|
-
this.defaultValue = defaultValue;
|
|
66091
|
-
}
|
|
66092
|
-
static boolean(defaultValue) {
|
|
66093
|
-
return new BooleanFlag(defaultValue);
|
|
66094
|
-
}
|
|
66095
|
-
static string(defaultValue) {
|
|
66096
|
-
return new StringFlag(defaultValue);
|
|
66097
|
-
}
|
|
66098
|
-
static number(defaultValue) {
|
|
66099
|
-
return new NumberFlag(defaultValue);
|
|
66100
|
-
}
|
|
66101
|
-
};
|
|
66102
|
-
var BooleanFlag = class extends Flag {
|
|
66103
|
-
parse(value) {
|
|
66104
|
-
if (typeof value === "string") {
|
|
66105
|
-
return ["true", "t", "1"].includes(value.toLowerCase());
|
|
66106
|
-
}
|
|
66107
|
-
if (typeof value === "boolean") {
|
|
66108
|
-
return value;
|
|
66109
|
-
}
|
|
66110
|
-
throw new Error(`could not parse value "${value}" as boolean`);
|
|
66111
|
-
}
|
|
66112
|
-
};
|
|
66113
|
-
var StringFlag = class extends Flag {
|
|
66114
|
-
parse(value) {
|
|
66115
|
-
if (typeof value === "string") {
|
|
66116
|
-
return value;
|
|
66117
|
-
}
|
|
66118
|
-
throw new Error(`could not parse value "${value}" as string`);
|
|
66119
|
-
}
|
|
66120
|
-
};
|
|
66121
|
-
var NumberFlag = class extends Flag {
|
|
66122
|
-
parse(value) {
|
|
66123
|
-
if (typeof value === "number") {
|
|
66124
|
-
return value;
|
|
66125
|
-
}
|
|
66126
|
-
if (typeof value === "string") {
|
|
66127
|
-
const parsed = parseFloat(value);
|
|
66128
|
-
if (!isNaN(parsed)) {
|
|
66129
|
-
return parsed;
|
|
66130
|
-
}
|
|
66131
|
-
}
|
|
66132
|
-
throw new Error(`could not parse value "${value}" as number`);
|
|
66133
|
-
}
|
|
66134
|
-
};
|
|
66135
|
-
var FlagSet = class {
|
|
66136
|
-
constructor(flagSchema) {
|
|
66137
|
-
this.flagSchema = flagSchema;
|
|
66138
|
-
this.setId = crypto.randomUUID();
|
|
66139
|
-
}
|
|
66140
|
-
defaults() {
|
|
66141
|
-
return Object.keys(this.flagSchema).reduce((acc, key) => {
|
|
66142
|
-
const typedKey = key;
|
|
66143
|
-
acc[typedKey] = this.flagSchema[key].defaultValue;
|
|
66144
|
-
return acc;
|
|
66145
|
-
}, {});
|
|
66146
|
-
}
|
|
66147
|
-
isFlagName(name) {
|
|
66148
|
-
return this.flagSchema[name] !== void 0;
|
|
66149
|
-
}
|
|
66150
|
-
async get(key, ctx) {
|
|
66151
|
-
const flags2 = await this.fetch(ctx);
|
|
66152
|
-
return flags2[key];
|
|
66153
|
-
}
|
|
66154
|
-
async isEnabled(key, ctx) {
|
|
66155
|
-
const flags2 = await this.fetch(ctx);
|
|
66156
|
-
return flags2[key];
|
|
66157
|
-
}
|
|
66158
|
-
async fetch(ctx) {
|
|
66159
|
-
return await import_dd_trace3.default.trace("features.fetch", async (span) => {
|
|
66160
|
-
const cachedFlags = getFeatureFlags(this.setId);
|
|
66161
|
-
if (cachedFlags) {
|
|
66162
|
-
span?.addTags({ fromCache: true });
|
|
66163
|
-
return cachedFlags;
|
|
66164
|
-
}
|
|
66165
|
-
const tags = {};
|
|
66166
|
-
const flagValues = this.defaults();
|
|
66167
|
-
const currentTenantId = getTenantId();
|
|
66168
|
-
const specificallySetFalse = /* @__PURE__ */ new Set();
|
|
66169
|
-
const split = (environment_default.TENANT_FEATURE_FLAGS || "").split(",").map((x) => x.split(":"));
|
|
66170
|
-
for (const [tenantId, ...features] of split) {
|
|
66171
|
-
if (!tenantId || tenantId !== "*" && tenantId !== currentTenantId) {
|
|
66172
|
-
continue;
|
|
66173
|
-
}
|
|
66174
|
-
tags[`readFromEnvironmentVars`] = true;
|
|
66175
|
-
for (let feature of features) {
|
|
66176
|
-
let value = true;
|
|
66177
|
-
if (feature.startsWith("!")) {
|
|
66178
|
-
feature = feature.slice(1);
|
|
66179
|
-
value = false;
|
|
66180
|
-
specificallySetFalse.add(feature);
|
|
66181
|
-
}
|
|
66182
|
-
if (!this.isFlagName(feature)) {
|
|
66183
|
-
continue;
|
|
66184
|
-
}
|
|
66185
|
-
if (typeof flagValues[feature] !== "boolean") {
|
|
66186
|
-
throw new Error(`Feature: ${feature} is not a boolean`);
|
|
66187
|
-
}
|
|
66188
|
-
flagValues[feature] = value;
|
|
66189
|
-
tags[`flags.${feature}.source`] = "environment";
|
|
66190
|
-
}
|
|
66191
|
-
}
|
|
66192
|
-
const license = ctx?.user?.license;
|
|
66193
|
-
if (license) {
|
|
66194
|
-
tags[`readFromLicense`] = true;
|
|
66195
|
-
for (const feature of license.features) {
|
|
66196
|
-
if (!this.isFlagName(feature)) {
|
|
66197
|
-
continue;
|
|
66198
|
-
}
|
|
66199
|
-
if (flagValues[feature] === true || specificallySetFalse.has(feature)) {
|
|
66200
|
-
continue;
|
|
66201
|
-
}
|
|
66202
|
-
flagValues[feature] = true;
|
|
66203
|
-
tags[`flags.${feature}.source`] = "license";
|
|
66204
|
-
}
|
|
66205
|
-
}
|
|
66206
|
-
const identity = getIdentity();
|
|
66207
|
-
tags[`identity.type`] = identity?.type;
|
|
66208
|
-
tags[`identity.tenantId`] = identity?.tenantId;
|
|
66209
|
-
tags[`identity._id`] = identity?._id;
|
|
66210
|
-
if (posthog && identity?.type === "user" /* USER */) {
|
|
66211
|
-
tags[`readFromPostHog`] = true;
|
|
66212
|
-
const personProperties = {};
|
|
66213
|
-
if (identity.tenantId) {
|
|
66214
|
-
personProperties.tenantId = identity.tenantId;
|
|
66215
|
-
}
|
|
66216
|
-
const posthogFlags = await posthog.getAllFlagsAndPayloads(
|
|
66217
|
-
identity._id,
|
|
66218
|
-
{
|
|
66219
|
-
personProperties
|
|
66220
|
-
}
|
|
66221
|
-
);
|
|
66222
|
-
for (const [name, value] of Object.entries(posthogFlags.featureFlags)) {
|
|
66223
|
-
if (!this.isFlagName(name)) {
|
|
66224
|
-
console.warn(`Unexpected posthog flag "${name}": ${value}`);
|
|
66225
|
-
continue;
|
|
66226
|
-
}
|
|
66227
|
-
if (flagValues[name] === true || specificallySetFalse.has(name)) {
|
|
66228
|
-
continue;
|
|
66229
|
-
}
|
|
66230
|
-
const payload = posthogFlags.featureFlagPayloads?.[name];
|
|
66231
|
-
const flag = this.flagSchema[name];
|
|
66232
|
-
try {
|
|
66233
|
-
flagValues[name] = flag.parse(payload || value);
|
|
66234
|
-
tags[`flags.${name}.source`] = "posthog";
|
|
66235
|
-
} catch (err) {
|
|
66236
|
-
console.warn(`Error parsing posthog flag "${name}": ${value}`, err);
|
|
66237
|
-
}
|
|
66238
|
-
}
|
|
66239
|
-
}
|
|
66240
|
-
setFeatureFlags(this.setId, flagValues);
|
|
66241
|
-
for (const [key, value] of Object.entries(flagValues)) {
|
|
66242
|
-
tags[`flags.${key}.value`] = value;
|
|
66243
|
-
}
|
|
66244
|
-
span?.addTags(tags);
|
|
66245
|
-
return flagValues;
|
|
66246
|
-
});
|
|
66247
|
-
}
|
|
66248
|
-
};
|
|
66249
|
-
var flags = new FlagSet({
|
|
66250
|
-
DEFAULT_VALUES: Flag.boolean(false)
|
|
66251
|
-
});
|
|
66252
|
-
|
|
66253
66275
|
// src/auth/index.ts
|
|
66254
66276
|
var auth_exports = {};
|
|
66255
66277
|
__export(auth_exports, {
|
|
@@ -67674,7 +67696,7 @@ var DocumentUpdateProcessor = class {
|
|
|
67674
67696
|
}
|
|
67675
67697
|
}
|
|
67676
67698
|
shutdown() {
|
|
67677
|
-
return
|
|
67699
|
+
return shutdown4();
|
|
67678
67700
|
}
|
|
67679
67701
|
};
|
|
67680
67702
|
|
|
@@ -67683,7 +67705,7 @@ var processingPromise;
|
|
|
67683
67705
|
var documentProcessor;
|
|
67684
67706
|
function init9(processors2) {
|
|
67685
67707
|
if (!asyncEventQueue) {
|
|
67686
|
-
|
|
67708
|
+
init6();
|
|
67687
67709
|
}
|
|
67688
67710
|
if (!documentProcessor) {
|
|
67689
67711
|
documentProcessor = new DocumentUpdateProcessor(processors2);
|