@ductape/sdk 0.0.4-v46 → 0.0.4-v49
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/README.md +1 -1
- package/dist/api/services/appApi.service.js +1 -1
- package/dist/api/services/appApi.service.js.map +1 -1
- package/dist/api/services/productsApi.service.d.ts +1 -0
- package/dist/api/services/productsApi.service.js +30 -2
- package/dist/api/services/productsApi.service.js.map +1 -1
- package/dist/api/services/workspaceSecretsApi.service.d.ts +75 -0
- package/dist/api/services/workspaceSecretsApi.service.js +62 -0
- package/dist/api/services/workspaceSecretsApi.service.js.map +1 -0
- package/dist/api/utils/cache.utils.js +10 -4
- package/dist/api/utils/cache.utils.js.map +1 -1
- package/dist/apps/services/app.service.js +5 -1
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/database/adapters/base.adapter.d.ts +8 -8
- package/dist/database/adapters/base.adapter.js.map +1 -1
- package/dist/database/adapters/dynamodb.adapter.d.ts +7 -7
- package/dist/database/adapters/dynamodb.adapter.js +174 -35
- package/dist/database/adapters/dynamodb.adapter.js.map +1 -1
- package/dist/database/adapters/mongodb.adapter.d.ts +7 -7
- package/dist/database/adapters/mongodb.adapter.js +263 -73
- package/dist/database/adapters/mongodb.adapter.js.map +1 -1
- package/dist/database/adapters/mysql.adapter.d.ts +7 -7
- package/dist/database/adapters/mysql.adapter.js +117 -42
- package/dist/database/adapters/mysql.adapter.js.map +1 -1
- package/dist/database/adapters/postgresql.adapter.d.ts +7 -7
- package/dist/database/adapters/postgresql.adapter.js +194 -63
- package/dist/database/adapters/postgresql.adapter.js.map +1 -1
- package/dist/database/database.service.d.ts +38 -1
- package/dist/database/database.service.js +307 -7
- package/dist/database/database.service.js.map +1 -1
- package/dist/database/types/aggregation.types.d.ts +73 -14
- package/dist/database/types/database.types.d.ts +2 -1
- package/dist/database/types/database.types.js +2 -1
- package/dist/database/types/database.types.js.map +1 -1
- package/dist/database/types/result.types.d.ts +2 -0
- package/dist/database/utils/transaction.js +2 -2
- package/dist/database/utils/transaction.js.map +1 -1
- package/dist/graph/adapters/arangodb.adapter.d.ts +80 -0
- package/dist/graph/adapters/arangodb.adapter.js +1393 -0
- package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
- package/dist/graph/adapters/base.adapter.d.ts +228 -0
- package/dist/graph/adapters/base.adapter.js +38 -0
- package/dist/graph/adapters/base.adapter.js.map +1 -0
- package/dist/graph/adapters/index.d.ts +10 -0
- package/dist/graph/adapters/index.js +23 -0
- package/dist/graph/adapters/index.js.map +1 -0
- package/dist/graph/adapters/memgraph.adapter.d.ts +85 -0
- package/dist/graph/adapters/memgraph.adapter.js +1491 -0
- package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
- package/dist/graph/adapters/neo4j.adapter.d.ts +88 -0
- package/dist/graph/adapters/neo4j.adapter.js +1861 -0
- package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
- package/dist/graph/adapters/neptune.adapter.d.ts +87 -0
- package/dist/graph/adapters/neptune.adapter.js +1430 -0
- package/dist/graph/adapters/neptune.adapter.js.map +1 -0
- package/dist/graph/graph.service.d.ts +278 -0
- package/dist/graph/graph.service.js +687 -0
- package/dist/graph/graph.service.js.map +1 -0
- package/dist/graph/index.d.ts +11 -0
- package/dist/graph/index.js +42 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/types/connection.types.d.ts +158 -0
- package/dist/graph/types/connection.types.js +43 -0
- package/dist/graph/types/connection.types.js.map +1 -0
- package/dist/graph/types/graph.types.d.ts +144 -0
- package/dist/graph/types/graph.types.js +84 -0
- package/dist/graph/types/graph.types.js.map +1 -0
- package/dist/graph/types/index.d.ts +11 -0
- package/dist/graph/types/index.js +35 -0
- package/dist/graph/types/index.js.map +1 -0
- package/dist/graph/types/node.types.d.ts +193 -0
- package/dist/graph/types/node.types.js +49 -0
- package/dist/graph/types/node.types.js.map +1 -0
- package/dist/graph/types/path.types.d.ts +224 -0
- package/dist/graph/types/path.types.js +38 -0
- package/dist/graph/types/path.types.js.map +1 -0
- package/dist/graph/types/query.types.d.ts +247 -0
- package/dist/graph/types/query.types.js +23 -0
- package/dist/graph/types/query.types.js.map +1 -0
- package/dist/graph/types/relationship.types.d.ts +224 -0
- package/dist/graph/types/relationship.types.js +35 -0
- package/dist/graph/types/relationship.types.js.map +1 -0
- package/dist/graph/types/result.types.d.ts +237 -0
- package/dist/graph/types/result.types.js +7 -0
- package/dist/graph/types/result.types.js.map +1 -0
- package/dist/graph/validators/index.d.ts +81 -0
- package/dist/graph/validators/index.js +243 -0
- package/dist/graph/validators/index.js.map +1 -0
- package/dist/index.d.ts +132 -1
- package/dist/index.js +207 -0
- package/dist/index.js.map +1 -1
- package/dist/logs/logs.types.d.ts +1 -0
- package/dist/logs/logs.types.js +1 -0
- package/dist/logs/logs.types.js.map +1 -1
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/products/services/products.service.d.ts +17 -1
- package/dist/products/services/products.service.js +240 -41
- package/dist/products/services/products.service.js.map +1 -1
- package/dist/products/validators/index.d.ts +3 -1
- package/dist/products/validators/index.js +5 -1
- package/dist/products/validators/index.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +15 -4
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +501 -109
- package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/create.productGraph.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/create.productGraph.validator.js +82 -0
- package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.d.ts +14 -0
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js +696 -0
- package/dist/products/validators/joi-validators/create.productGraphAction.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.d.ts +6 -0
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +28 -26
- package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -1
- package/dist/products/validators/joi-validators/update.productGraph.validator.d.ts +3 -0
- package/dist/products/validators/joi-validators/update.productGraph.validator.js +87 -0
- package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.d.ts +7 -0
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js +72 -0
- package/dist/products/validators/joi-validators/update.productGraphAction.validator.js.map +1 -0
- package/dist/types/enums.d.ts +2 -1
- package/dist/types/enums.js +1 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/productsBuilder.types.d.ts +80 -6
- package/dist/types/productsBuilder.types.js +61 -4
- package/dist/types/productsBuilder.types.js.map +1 -1
- package/package.json +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IApp, IAppAccess, IAppAction, IAppWebhook, ISample, IVersion } from '../../types/appBuilder.types';
|
|
2
2
|
import { IBuilderInit } from '../../types/index.types';
|
|
3
|
-
import { IActionDataParserInput, IActionRequest, ICreateProductsBuilder, IFeatureEvent, IFeatureInput, IFeatureSequence, IProduct, IProductApp, IProductCache, IProductDatabase, IProductDatabaseAction, IProductEnv, IProductFeature, IProductFunction, IProductJobs, IParseActionEventInput, IParseInputStringInput, IParseInputStringMetaData, IProductStorage, IDbActionRequest, INotificationRequest, IProductQuota, IProductFallback, IProductDatabaseMigration, IQuotaOptions, IFallbackOptions, IProductSession, IFetchFilesPayload, IFetchUsersPayload, IProductAppHealth } from '../../types/productsBuilder.types';
|
|
3
|
+
import { IActionDataParserInput, IActionRequest, ICreateProductsBuilder, IFeatureEvent, IFeatureInput, IFeatureSequence, IProduct, IProductApp, IProductCache, IProductDatabase, IProductDatabaseAction, IProductEnv, IProductFeature, IProductFunction, IProductJobs, IParseActionEventInput, IParseInputStringInput, IParseInputStringMetaData, IProductStorage, IDbActionRequest, INotificationRequest, IProductQuota, IProductFallback, IProductDatabaseMigration, IProductGraph, IProductGraphAction, IQuotaOptions, IFallbackOptions, IProductSession, IFetchFilesPayload, IFetchUsersPayload, IProductAppHealth } from '../../types/productsBuilder.types';
|
|
4
4
|
import { KeyValuePair } from '../../imports/imports.types';
|
|
5
5
|
import { IProductNotification, INotificationEnv, IProductNotificationTemplate, IProductMessageBroker, IProductMessageBrokerTopic, IFileURLPayload } from '../../types/processor.types';
|
|
6
6
|
import { IParsedSample } from '../../types/inputs.types';
|
|
@@ -78,6 +78,14 @@ export interface IProductsBuilderService {
|
|
|
78
78
|
updateDatabaseMigration(data: Partial<IProductDatabaseMigration>): Promise<void>;
|
|
79
79
|
fetchDatabaseMigration(tag: string): Promise<IProductDatabaseMigration | null>;
|
|
80
80
|
fetchDatabaseMigrations(databaseTag: string): Promise<Array<IProductDatabaseMigration>>;
|
|
81
|
+
createGraph(data: Partial<IProductGraph>, throwErrorIfExists?: boolean): Promise<void>;
|
|
82
|
+
updateGraph(tag: string, data: Partial<IProductGraph>): Promise<void>;
|
|
83
|
+
fetchGraph(tag: string): Promise<IProductGraph | null>;
|
|
84
|
+
fetchGraphs(): Promise<Array<IProductGraph>>;
|
|
85
|
+
createGraphAction(data: Partial<IProductGraphAction>, throwErrorIfExists?: boolean): Promise<void>;
|
|
86
|
+
updateGraphAction(data: Partial<IProductGraphAction>): Promise<void>;
|
|
87
|
+
fetchGraphAction(tag: string): Promise<IProductGraphAction | null>;
|
|
88
|
+
fetchGraphActions(graphTag: string): Promise<Array<IProductGraphAction>>;
|
|
81
89
|
createJob(data: Partial<IProductJobs>, throwErrorIfExists?: boolean): Promise<void>;
|
|
82
90
|
updateJob(tag: string, data: Partial<IProductJobs>): Promise<void>;
|
|
83
91
|
fetchJob(tag: string): Promise<IProductJobs>;
|
|
@@ -246,6 +254,14 @@ export default class ProductsBuilderService implements IProductsBuilderService {
|
|
|
246
254
|
updateDatabase(tag: string, data: Partial<IProductDatabase>): Promise<void>;
|
|
247
255
|
fetchDatabases(): Promise<Array<IProductDatabase>>;
|
|
248
256
|
fetchDatabase(tag: string): Promise<IProductDatabase | null>;
|
|
257
|
+
createGraph(data: Partial<IProductGraph>, throwErrorIfExists?: boolean): Promise<void>;
|
|
258
|
+
updateGraph(tag: string, data: Partial<IProductGraph>): Promise<void>;
|
|
259
|
+
fetchGraphs(): Promise<Array<IProductGraph>>;
|
|
260
|
+
fetchGraph(tag: string): Promise<IProductGraph | null>;
|
|
261
|
+
createGraphAction(data: Partial<IProductGraphAction>, throwErrorIfExists?: boolean): Promise<void>;
|
|
262
|
+
updateGraphAction(data: Partial<IProductGraphAction>): Promise<void>;
|
|
263
|
+
fetchGraphAction(tag: string, throwErrorIfNotExists?: boolean): Promise<IProductGraphAction | null>;
|
|
264
|
+
fetchGraphActions(graphTag: string): Promise<Array<IProductGraphAction>>;
|
|
249
265
|
createDatabaseAction(data: Partial<IProductDatabaseAction>, throwErrorIfExists?: boolean): Promise<void>;
|
|
250
266
|
fetchDatabaseAction(tag: string, throwErrorIfExists?: boolean): Promise<IProductDatabaseAction | null>;
|
|
251
267
|
updateDatabaseAction(data: Partial<IProductDatabaseAction>): Promise<void>;
|
|
@@ -24,8 +24,8 @@ const productsBuilder_types_1 = require("../../types/productsBuilder.types");
|
|
|
24
24
|
const validators_1 = require("../validators");
|
|
25
25
|
const objects_utils_1 = require("./utils/objects.utils");
|
|
26
26
|
const processor_utils_1 = require("../../processor/utils/processor.utils");
|
|
27
|
-
const create_productDatabaseAction_validator_1 = require("../validators/joi-validators/create.productDatabaseAction.validator");
|
|
28
|
-
const update_productDatabaseAction_validator_1 = require("../validators/joi-validators/update.productDatabaseAction.validator");
|
|
27
|
+
const create_productDatabaseAction_validator_1 = __importDefault(require("../validators/joi-validators/create.productDatabaseAction.validator"));
|
|
28
|
+
const update_productDatabaseAction_validator_1 = __importDefault(require("../validators/joi-validators/update.productDatabaseAction.validator"));
|
|
29
29
|
const create_productStorage_validator_1 = require("../validators/joi-validators/create.productStorage.validator");
|
|
30
30
|
const inputs_types_1 = require("../../types/inputs.types");
|
|
31
31
|
const string_utils_1 = require("./utils/string.utils");
|
|
@@ -36,6 +36,8 @@ const update_productDatabaseMigration_validator_1 = __importDefault(require("../
|
|
|
36
36
|
const create_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/create.productNotificationMessage.validator"));
|
|
37
37
|
const create_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/create.productMessageBrokerTopic.validator"));
|
|
38
38
|
const update_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/update.productMessageBrokerTopic.validator"));
|
|
39
|
+
const create_productGraphAction_validator_1 = __importDefault(require("../validators/joi-validators/create.productGraphAction.validator"));
|
|
40
|
+
const update_productGraphAction_validator_1 = __importDefault(require("../validators/joi-validators/update.productGraphAction.validator"));
|
|
39
41
|
const update_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/update.productNotificationMessage.validator"));
|
|
40
42
|
const create_productNotification_validator_1 = require("../validators/joi-validators/create.productNotification.validator");
|
|
41
43
|
const functions_utils_1 = require("./utils/functions.utils");
|
|
@@ -2948,6 +2950,217 @@ class ProductsBuilderService {
|
|
|
2948
2950
|
});
|
|
2949
2951
|
return database;
|
|
2950
2952
|
}
|
|
2953
|
+
// ==================== GRAPH DATABASE METHODS ====================
|
|
2954
|
+
async createGraph(data, throwErrorIfExists = false) {
|
|
2955
|
+
try {
|
|
2956
|
+
if (!(await this.fetchGraph(data.tag))) {
|
|
2957
|
+
await validators_1.CreateProductGraphSchema.validateAsync(data);
|
|
2958
|
+
const processedEnvs = [];
|
|
2959
|
+
for (const env of data.envs) {
|
|
2960
|
+
const exists = await this.fetchEnv(env.slug);
|
|
2961
|
+
if (!exists) {
|
|
2962
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
2963
|
+
}
|
|
2964
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
2965
|
+
processedEnvs.push(env);
|
|
2966
|
+
}
|
|
2967
|
+
data.envs = processedEnvs;
|
|
2968
|
+
const envs = await this.fetchEnvs();
|
|
2969
|
+
for (const env of envs) {
|
|
2970
|
+
const exists = data.envs.findIndex((graphEnv) => graphEnv.slug === env.slug);
|
|
2971
|
+
if (exists === -1) {
|
|
2972
|
+
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.GRAPH, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
2976
|
+
}
|
|
2977
|
+
else {
|
|
2978
|
+
if (throwErrorIfExists)
|
|
2979
|
+
throw new Error(`Graph ${data.tag} already exists`);
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
catch (e) {
|
|
2983
|
+
throw e;
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
async updateGraph(tag, data) {
|
|
2987
|
+
try {
|
|
2988
|
+
const graph = await this.fetchGraph(tag);
|
|
2989
|
+
if (!graph) {
|
|
2990
|
+
throw new Error(`Graph ${tag} not found`);
|
|
2991
|
+
}
|
|
2992
|
+
const { _id, envs } = graph;
|
|
2993
|
+
await validators_1.UpdateProductGraphSchema.validateAsync(data);
|
|
2994
|
+
if (data.tag && (await this.fetchGraph(data.tag))) {
|
|
2995
|
+
throw new Error(`tag ${data.tag} is in use`);
|
|
2996
|
+
}
|
|
2997
|
+
if (data.envs) {
|
|
2998
|
+
data.envs = await Promise.all(data.envs.map(async (env) => {
|
|
2999
|
+
const exists = await this.fetchEnv(env.slug);
|
|
3000
|
+
if (!exists) {
|
|
3001
|
+
throw new Error(`Env ${env.slug} does not exist`);
|
|
3002
|
+
}
|
|
3003
|
+
if (env.connection_url) {
|
|
3004
|
+
env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
|
|
3005
|
+
}
|
|
3006
|
+
return env;
|
|
3007
|
+
}));
|
|
3008
|
+
const overwrite = [];
|
|
3009
|
+
const newEnvs = [];
|
|
3010
|
+
data.envs.map((dataEnv) => {
|
|
3011
|
+
const existsIndex = envs.findIndex((env) => env.slug === dataEnv.slug);
|
|
3012
|
+
if (!(this.fetchEnv(dataEnv.slug))) {
|
|
3013
|
+
throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
|
|
3014
|
+
}
|
|
3015
|
+
if (existsIndex === -1) {
|
|
3016
|
+
if (!dataEnv.connection_url) {
|
|
3017
|
+
throw new Error(`connection_url is required for new env ${dataEnv.slug}`);
|
|
3018
|
+
}
|
|
3019
|
+
newEnvs.push(dataEnv);
|
|
3020
|
+
}
|
|
3021
|
+
else {
|
|
3022
|
+
overwrite.push(Object.assign(Object.assign({}, envs[existsIndex]), dataEnv));
|
|
3023
|
+
}
|
|
3024
|
+
});
|
|
3025
|
+
const unchanged = [];
|
|
3026
|
+
envs.map((env) => {
|
|
3027
|
+
const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
3028
|
+
const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
|
|
3029
|
+
if (!newEnv && !overwriteEnv) {
|
|
3030
|
+
unchanged.push(env);
|
|
3031
|
+
}
|
|
3032
|
+
});
|
|
3033
|
+
data.envs = [...unchanged, ...overwrite, ...newEnvs];
|
|
3034
|
+
}
|
|
3035
|
+
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { tag, component: enums_1.ProductComponents.GRAPH, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
|
|
3036
|
+
}
|
|
3037
|
+
catch (e) {
|
|
3038
|
+
throw e;
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
async fetchGraphs() {
|
|
3042
|
+
const components = await this.productApi.fetchProductComponents(this.product_id, 'graph', this.getUserAccess());
|
|
3043
|
+
components.map((graph) => {
|
|
3044
|
+
graph.envs.map((env) => {
|
|
3045
|
+
env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key);
|
|
3046
|
+
});
|
|
3047
|
+
});
|
|
3048
|
+
return components;
|
|
3049
|
+
}
|
|
3050
|
+
async fetchGraph(tag) {
|
|
3051
|
+
const graph = await this.productApi.fetchProductComponentByTag(this.product_id, 'graph', tag, this.getUserAccess());
|
|
3052
|
+
if (graph && graph.envs) {
|
|
3053
|
+
graph.envs.map((env) => {
|
|
3054
|
+
env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key);
|
|
3055
|
+
});
|
|
3056
|
+
}
|
|
3057
|
+
return graph;
|
|
3058
|
+
}
|
|
3059
|
+
// ==================== GRAPH ACTION METHODS ====================
|
|
3060
|
+
async createGraphAction(data, throwErrorIfExists = false) {
|
|
3061
|
+
var _a;
|
|
3062
|
+
try {
|
|
3063
|
+
if (!data.tag) {
|
|
3064
|
+
throw new Error('tag field is required');
|
|
3065
|
+
}
|
|
3066
|
+
const [graphTag, tag] = data.tag.split(':');
|
|
3067
|
+
if (!graphTag || !tag) {
|
|
3068
|
+
throw new Error('tag should be formatted as graph_tag:action_tag');
|
|
3069
|
+
}
|
|
3070
|
+
const graph = await this.fetchGraph(graphTag);
|
|
3071
|
+
if (!graph) {
|
|
3072
|
+
throw new Error(`Graph ${graphTag} not found`);
|
|
3073
|
+
}
|
|
3074
|
+
const existingAction = (_a = graph.actions) === null || _a === void 0 ? void 0 : _a.find((action) => action.tag === tag);
|
|
3075
|
+
if (existingAction) {
|
|
3076
|
+
if (throwErrorIfExists) {
|
|
3077
|
+
throw new Error(`Graph action ${data.tag} already exists`);
|
|
3078
|
+
}
|
|
3079
|
+
return;
|
|
3080
|
+
}
|
|
3081
|
+
// Validate the action data
|
|
3082
|
+
const validationData = Object.assign(Object.assign({}, data), { tag });
|
|
3083
|
+
await create_productGraphAction_validator_1.default.validateAsync(validationData);
|
|
3084
|
+
// Extract placeholders from template
|
|
3085
|
+
const values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
|
|
3086
|
+
const template = JSON.stringify(data.template);
|
|
3087
|
+
// Process filter template if provided
|
|
3088
|
+
let filterData, filterTemplate;
|
|
3089
|
+
if (data.filterTemplate) {
|
|
3090
|
+
filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
|
|
3091
|
+
filterTemplate = JSON.stringify(data.filterTemplate);
|
|
3092
|
+
}
|
|
3093
|
+
const actionData = Object.assign(Object.assign({}, data), { tag, data: values, template,
|
|
3094
|
+
filterData,
|
|
3095
|
+
filterTemplate });
|
|
3096
|
+
graph.actions = graph.actions || [];
|
|
3097
|
+
graph.actions.push(actionData);
|
|
3098
|
+
await this.updateGraph(graphTag, { actions: graph.actions });
|
|
3099
|
+
}
|
|
3100
|
+
catch (error) {
|
|
3101
|
+
throw new Error(`Failed to create graph action: ${error.message}`);
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
async updateGraphAction(data) {
|
|
3105
|
+
var _a;
|
|
3106
|
+
try {
|
|
3107
|
+
if (!data.tag) {
|
|
3108
|
+
throw new Error('tag field is required');
|
|
3109
|
+
}
|
|
3110
|
+
const [graphTag, tag] = data.tag.split(':');
|
|
3111
|
+
if (!graphTag || !tag) {
|
|
3112
|
+
throw new Error('tag should be formatted as graph_tag:action_tag');
|
|
3113
|
+
}
|
|
3114
|
+
const graph = await this.fetchGraph(graphTag);
|
|
3115
|
+
if (!graph) {
|
|
3116
|
+
throw new Error(`Graph ${graphTag} not found`);
|
|
3117
|
+
}
|
|
3118
|
+
const actionIndex = (_a = graph.actions) === null || _a === void 0 ? void 0 : _a.findIndex((action) => action.tag === tag);
|
|
3119
|
+
if (actionIndex === undefined || actionIndex === -1) {
|
|
3120
|
+
throw new Error(`Graph action ${data.tag} not found`);
|
|
3121
|
+
}
|
|
3122
|
+
// Validate the update data
|
|
3123
|
+
const validationData = Object.assign(Object.assign({}, data), { tag });
|
|
3124
|
+
await update_productGraphAction_validator_1.default.validateAsync(validationData);
|
|
3125
|
+
// Process template if provided
|
|
3126
|
+
const updateData = Object.assign(Object.assign({}, data), { tag });
|
|
3127
|
+
if (data.template) {
|
|
3128
|
+
updateData.data = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
|
|
3129
|
+
updateData.template = JSON.stringify(data.template);
|
|
3130
|
+
}
|
|
3131
|
+
// Process filter template if provided
|
|
3132
|
+
if (data.filterTemplate) {
|
|
3133
|
+
updateData.filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
|
|
3134
|
+
updateData.filterTemplate = JSON.stringify(data.filterTemplate);
|
|
3135
|
+
}
|
|
3136
|
+
graph.actions[actionIndex] = Object.assign(Object.assign({}, graph.actions[actionIndex]), updateData);
|
|
3137
|
+
await this.updateGraph(graphTag, { actions: graph.actions });
|
|
3138
|
+
}
|
|
3139
|
+
catch (error) {
|
|
3140
|
+
throw new Error(`Failed to update graph action: ${error.message}`);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
async fetchGraphAction(tag, throwErrorIfNotExists = false) {
|
|
3144
|
+
var _a, _b;
|
|
3145
|
+
const [graphTag, actionTag] = tag.split(':');
|
|
3146
|
+
if (!graphTag || !actionTag) {
|
|
3147
|
+
throw new Error('tag is expected to be defined as "graph_tag:action_tag"');
|
|
3148
|
+
}
|
|
3149
|
+
const graph = (_a = this.product.graphs) === null || _a === void 0 ? void 0 : _a.find((data) => data.tag === graphTag);
|
|
3150
|
+
if (!graph)
|
|
3151
|
+
throw new Error(`Graph ${graphTag} not found`);
|
|
3152
|
+
const action = (_b = graph.actions) === null || _b === void 0 ? void 0 : _b.find((data) => data.tag === actionTag);
|
|
3153
|
+
if (!action && throwErrorIfNotExists)
|
|
3154
|
+
throw new Error(`Graph action ${tag} not found`);
|
|
3155
|
+
return action || null;
|
|
3156
|
+
}
|
|
3157
|
+
async fetchGraphActions(graphTag) {
|
|
3158
|
+
const graph = await this.fetchGraph(graphTag);
|
|
3159
|
+
if (!graph) {
|
|
3160
|
+
throw new Error(`Graph ${graphTag} not found`);
|
|
3161
|
+
}
|
|
3162
|
+
return graph.actions || [];
|
|
3163
|
+
}
|
|
2951
3164
|
async createDatabaseAction(data, throwErrorIfExists = false) {
|
|
2952
3165
|
try {
|
|
2953
3166
|
if (!data.tag) {
|
|
@@ -2960,27 +3173,18 @@ class ProductsBuilderService {
|
|
|
2960
3173
|
const exists = await this.fetchDatabaseAction(data.tag);
|
|
2961
3174
|
data.tag = tag;
|
|
2962
3175
|
if (!exists) {
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
else {
|
|
2978
|
-
create_productDatabaseAction_validator_1.SQLDatabaseActionSchema.validateAsync(data);
|
|
2979
|
-
values = (0, string_utils_1.extractPlaceholders)(String(data.template));
|
|
2980
|
-
template = data.template;
|
|
2981
|
-
if (data.filterTemplate) {
|
|
2982
|
-
data.filterData = (0, string_utils_1.extractPlaceholders)(String(data.filterTemplate));
|
|
2983
|
-
}
|
|
3176
|
+
// Verify database exists
|
|
3177
|
+
await this.fetchDatabase(databaseTag);
|
|
3178
|
+
// Validate the action data using the unified schema
|
|
3179
|
+
const validationData = Object.assign(Object.assign({}, data), { tag });
|
|
3180
|
+
await create_productDatabaseAction_validator_1.default.validateAsync(validationData);
|
|
3181
|
+
// Extract placeholders from the structured template
|
|
3182
|
+
const values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
|
|
3183
|
+
const template = JSON.stringify(data.template);
|
|
3184
|
+
// Process filter template if provided (for UPDATE/DELETE actions)
|
|
3185
|
+
if (data.filterTemplate) {
|
|
3186
|
+
data.filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
|
|
3187
|
+
data.filterTemplate = JSON.stringify(data.filterTemplate);
|
|
2984
3188
|
}
|
|
2985
3189
|
await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { data: values, template,
|
|
2986
3190
|
databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
|
|
@@ -3020,32 +3224,27 @@ class ProductsBuilderService {
|
|
|
3020
3224
|
if (!databaseTag || !tag) {
|
|
3021
3225
|
throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
|
|
3022
3226
|
}
|
|
3023
|
-
// Fetch required data
|
|
3024
|
-
|
|
3227
|
+
// Fetch required data (also verifies database exists)
|
|
3228
|
+
await this.fetchDatabase(databaseTag);
|
|
3025
3229
|
const action = await this.fetchDatabaseAction(data.tag, true);
|
|
3026
3230
|
// Construct payload
|
|
3027
3231
|
const payload = Object.assign(Object.assign(Object.assign({}, action), data), { databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.UPDATE });
|
|
3028
3232
|
// Validate and process the template
|
|
3029
3233
|
data.tag = tag;
|
|
3234
|
+
// Validate using the unified schema
|
|
3235
|
+
const validationData = Object.assign(Object.assign({}, data), { tag });
|
|
3236
|
+
await update_productDatabaseAction_validator_1.default.validateAsync(validationData);
|
|
3030
3237
|
if (data.template) {
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
|
|
3035
|
-
template = JSON.stringify(data.template);
|
|
3036
|
-
}
|
|
3037
|
-
else {
|
|
3038
|
-
await update_productDatabaseAction_validator_1.UpdateSQLDatabaseActionSchema.validateAsync(data);
|
|
3039
|
-
values = (0, string_utils_1.extractPlaceholders)(String(data.template));
|
|
3040
|
-
template = data.template;
|
|
3041
|
-
}
|
|
3238
|
+
// Extract placeholders from the structured template
|
|
3239
|
+
const values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
|
|
3240
|
+
const template = JSON.stringify(data.template);
|
|
3042
3241
|
Object.assign(payload, { data: values, template });
|
|
3043
3242
|
}
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3243
|
+
// Process filter template if provided
|
|
3244
|
+
if (data.filterTemplate) {
|
|
3245
|
+
const filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
|
|
3246
|
+
const filterTemplate = JSON.stringify(data.filterTemplate);
|
|
3247
|
+
Object.assign(payload, { filterData, filterTemplate });
|
|
3049
3248
|
}
|
|
3050
3249
|
// Update product and reinitialize
|
|
3051
3250
|
await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
|