blixify-server 0.2.9 → 0.2.11

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.
@@ -1,3 +1,4 @@
1
+ export { AuthWrapper } from "./authWrapper";
1
2
  export { CryptoMiddleware } from "./crypto";
2
3
  export { FirebaseWrapper } from "./fbWrapper";
3
4
  export { MondayWrapper } from "./mondayWrapper";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UploadWrapper = exports.TrackVisionWrapper = exports.SecurityMiddleware = exports.MongoWrapper = exports.MondayWrapper = exports.FirebaseWrapper = exports.CryptoMiddleware = void 0;
3
+ exports.UploadWrapper = exports.TrackVisionWrapper = exports.SecurityMiddleware = exports.MongoWrapper = exports.MondayWrapper = exports.FirebaseWrapper = exports.CryptoMiddleware = exports.AuthWrapper = void 0;
4
+ var authWrapper_1 = require("./authWrapper");
5
+ Object.defineProperty(exports, "AuthWrapper", { enumerable: true, get: function () { return authWrapper_1.AuthWrapper; } });
4
6
  var crypto_1 = require("./crypto");
5
7
  Object.defineProperty(exports, "CryptoMiddleware", { enumerable: true, get: function () { return crypto_1.CryptoMiddleware; } });
6
8
  var fbWrapper_1 = require("./fbWrapper");
@@ -45,6 +45,7 @@ export declare class MongoWrapper {
45
45
  initDelete: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<{
46
46
  success: boolean;
47
47
  } | undefined>;
48
+ handleBuildPipeline(req: any): any[];
48
49
  initList: (req: any, res: any) => Promise<{
49
50
  data: any[];
50
51
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAUA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AA6GD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,SAAM;IACb,KAAK,SAAM;IACX,WAAW,EAAE,GAAG,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC;IAEX,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAA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AAK,QAAQ,GAAG,CAAC;;mBAkDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBAuCjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAgKtC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqGtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA0I5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAwCtC;IAEF,mBAAmB,CAAC,GAAG,EAAE,GAAG;IAoM5B,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA2PlC;IAEF,IAAI,YA+EF;CACH"}
@@ -19,111 +19,98 @@ const QueryModel_1 = require("../model/QueryModel");
19
19
  const utils_1 = require("./utils");
20
20
  const handleParseQueryFilter = (queryList, prefix) => {
21
21
  const queryFilter = {};
22
- const queryGroupValues = {};
23
22
  if (queryList && queryList.length > 0) {
24
- queryList.map((eachQuery) => {
25
- var _a;
26
- let queryId = (_a = eachQuery.queryId) !== null && _a !== void 0 ? _a : "";
27
- if (prefix)
28
- queryId = `${prefix}.${queryId}`;
29
- const value = eachQuery.value;
30
- const queryValues = {};
31
- let orOption = false;
32
- switch (eachQuery.type) {
33
- case "search":
34
- if (eachQuery.searchIds && eachQuery.searchIds.length > 0) {
35
- eachQuery.searchIds.map((eachSearchId) => {
36
- orOption = true;
37
- queryValues[eachSearchId] = {
38
- $regex: `${(0, utils_1.handleSpecialWordsEscapeRegex)(value)}`,
23
+ queryList.forEach((eachQuery) => {
24
+ const orConditions = [];
25
+ if (eachQuery.type === "search") {
26
+ if (eachQuery.searchIds && eachQuery.searchIds.length > 0) {
27
+ eachQuery.searchIds.forEach((eachField) => {
28
+ const mainField = prefix ? `${prefix}.${eachField}` : eachField;
29
+ orConditions.push({
30
+ [mainField]: {
31
+ $regex: eachQuery.value
32
+ .toString()
33
+ .replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
39
34
  $options: "i",
40
- };
35
+ },
41
36
  });
37
+ });
38
+ }
39
+ if (eachQuery.foreign &&
40
+ eachQuery.foreign.searchFields &&
41
+ eachQuery.foreign.searchFields.length > 0) {
42
+ let foreignAlias = eachQuery.foreign.alias;
43
+ if (!foreignAlias) {
44
+ foreignAlias = eachQuery.foreign.localField;
42
45
  }
43
- break;
46
+ if (prefix) {
47
+ foreignAlias = `${prefix}.${foreignAlias}`;
48
+ }
49
+ eachQuery.foreign.searchFields.forEach((foreignField) => {
50
+ orConditions.push({
51
+ [`${foreignAlias}.${foreignField}`]: {
52
+ $regex: eachQuery.value
53
+ .toString()
54
+ .replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
55
+ $options: "i",
56
+ },
57
+ });
58
+ });
59
+ }
60
+ }
61
+ // For non-"search" types (like "=" or ">" etc.), use queryId.
62
+ let queryId = eachQuery.queryId || "";
63
+ if (prefix)
64
+ queryId = `${prefix}.${queryId}`;
65
+ switch (eachQuery.type) {
44
66
  case "=":
45
- queryValues[queryId] = value;
67
+ queryFilter[queryId] = eachQuery.value;
46
68
  break;
47
69
  case "!=":
48
- queryValues[queryId] = {
49
- $ne: value,
50
- };
70
+ queryFilter[queryId] = { $ne: eachQuery.value };
71
+ break;
72
+ case "in":
73
+ queryFilter[queryId] = { $in: eachQuery.value };
51
74
  break;
52
75
  case ">":
53
- queryValues[queryId] = {
54
- $gt: value,
55
- };
76
+ queryFilter[queryId] = { $gt: eachQuery.value };
56
77
  break;
57
78
  case "<":
58
- queryValues[queryId] = {
59
- $lt: value,
60
- };
79
+ queryFilter[queryId] = { $lt: eachQuery.value };
80
+ break;
81
+ case "!in":
82
+ queryFilter[queryId] = { $nin: eachQuery.value };
61
83
  break;
62
84
  case "><":
63
- if (Array.isArray(value) && value.length >= 2) {
64
- queryValues[queryId] = {
65
- $gte: value[0],
66
- $lte: value[1],
85
+ if (Array.isArray(eachQuery.value) && eachQuery.value.length >= 2) {
86
+ queryFilter[queryId] = {
87
+ [queryId]: {
88
+ $gte: eachQuery.value[0],
89
+ $lte: eachQuery.value[1],
90
+ },
67
91
  };
68
92
  }
69
93
  break;
70
- case "in":
71
- queryValues[queryId] = {
72
- $in: value,
73
- };
74
- break;
75
- case "!in":
76
- queryFilter[queryId] = {
77
- $nin: value,
78
- };
79
- break;
80
94
  case "exists":
81
- // Check if field exists or not
82
- queryValues[queryId] = {
83
- $exists: value, // `true` if field should exist, `false` if field should not exist
84
- };
95
+ queryFilter[queryId].push({
96
+ $exists: eachQuery.value, // `true` if field should exist, `false` if field should not exist
97
+ });
85
98
  break;
99
+ // Handle other cases as needed.
86
100
  default:
87
101
  break;
88
102
  }
89
- if (eachQuery.orQuery)
90
- orOption = true;
91
- //INFO : Delete Query Values as it's added outside
92
- if (eachQuery.orQueryGroupId) {
93
- const groupValue = queryValues[queryId];
94
- if (groupValue) {
95
- if (queryGroupValues[eachQuery.orQueryGroupId]) {
96
- queryGroupValues[eachQuery.orQueryGroupId]["$and"].push({
97
- [queryId]: queryValues[queryId],
98
- });
99
- }
100
- else {
101
- queryGroupValues[eachQuery.orQueryGroupId] = {
102
- $and: [{ [queryId]: queryValues[queryId] }],
103
- };
104
- }
105
- delete queryValues[queryId];
106
- }
107
- }
108
- Object.keys(queryValues).map((eachKey) => {
109
- if (orOption) {
110
- if (queryFilter["$or"])
111
- queryFilter["$or"].push({ [eachKey]: queryValues[eachKey] });
112
- else
113
- queryFilter["$or"] = [{ [eachKey]: queryValues[eachKey] }];
103
+ // If we have collected OR conditions for this query, add them to the overall filter.
104
+ if (orConditions.length > 0) {
105
+ if (queryFilter["$or"]) {
106
+ queryFilter["$or"] = queryFilter["$or"].concat(orConditions);
114
107
  }
115
108
  else {
116
- queryFilter[eachKey] = queryValues[eachKey];
109
+ queryFilter["$or"] = orConditions;
117
110
  }
118
- });
111
+ }
119
112
  });
120
113
  }
121
- Object.keys(queryGroupValues).map((eachKey) => {
122
- if (queryFilter["$or"])
123
- queryFilter["$or"].push(queryGroupValues[eachKey]);
124
- else
125
- queryFilter["$or"] = [queryGroupValues[eachKey]];
126
- });
127
114
  return queryFilter;
128
115
  };
129
116
  /**
@@ -319,9 +306,10 @@ class MongoWrapper {
319
306
  const mongoCollection = this.mongoDB
320
307
  .db(this.tableId)
321
308
  .collection(this.collection);
322
- const mongoData = yield mongoCollection.findOne({
323
- _id: valid,
309
+ const pipeline = this.handleBuildPipeline({
310
+ body: Object.assign(Object.assign({}, req.body), { query: [{ type: "=", queryId: "_id", value: valid }] }),
324
311
  });
312
+ const [mongoData] = yield mongoCollection.aggregate(pipeline).toArray();
325
313
  const validBaseConfig = (0, QueryModel_1.checkBaseConfig)(this.config, req);
326
314
  const validOpsConfig = (0, QueryModel_1.checkOpsConfig)(this.config, "read", req, mongoData);
327
315
  if (!validBaseConfig || !validOpsConfig) {
@@ -398,9 +386,6 @@ class MongoWrapper {
398
386
  break;
399
387
  case "><":
400
388
  if (Array.isArray(value) && value.length >= 2) {
401
- queryFilter[queryType].push({
402
- [queryId]: { $lt: value },
403
- });
404
389
  queryFilter[queryType] = {
405
390
  [queryId]: { $gte: value[0], $lte: value[1] },
406
391
  };
@@ -912,25 +897,14 @@ class MongoWrapper {
912
897
  const mongoCollection = this.mongoDB
913
898
  .db(this.tableId)
914
899
  .collection(this.collection);
915
- let mongoQuery = mongoCollection.find(queryFilter);
916
- const count = yield mongoQuery.count({});
917
- //INFO : Step 2 - Pagination
918
- if (req.body.cursor) {
919
- mongoQuery = mongoQuery.skip(req.body.cursor);
920
- }
921
- //INFO : Step 3 - Limit
922
- if (!req.body.stopLimit) {
923
- mongoQuery = mongoQuery.limit((_y = req.body.limit) !== null && _y !== void 0 ? _y : 10);
924
- }
925
- //INFO : Step 4 - Sort
926
- if (req.body.sort) {
927
- const sortReq = req.body.sort;
928
- const sortQuery = {
929
- [sortReq.sortId]: sortReq.type === "asc" ? 1 : -1,
930
- };
931
- mongoQuery = mongoQuery.sort(sortQuery);
932
- }
933
- const dataList = yield mongoQuery.toArray();
900
+ const pipeline = this.handleBuildPipeline(req);
901
+ const countPipeline = [...pipeline];
902
+ countPipeline.push({ $count: "total" });
903
+ const [dataList, countResult] = yield Promise.all([
904
+ mongoCollection.aggregate(pipeline).toArray(),
905
+ mongoCollection.aggregate(countPipeline).toArray(),
906
+ ]);
907
+ const count = ((_y = countResult[0]) === null || _y === void 0 ? void 0 : _y.total) || 0;
934
908
  //INFO : Security Checker
935
909
  let validOpsConfig = true;
936
910
  if (dataList.length > 0) {
@@ -958,7 +932,9 @@ class MongoWrapper {
958
932
  }
959
933
  }
960
934
  catch (err) {
961
- res.status(400).json({ err: err });
935
+ res.status(400).json({
936
+ err: err.message,
937
+ });
962
938
  }
963
939
  });
964
940
  this.init = () => {
@@ -1044,5 +1020,165 @@ class MongoWrapper {
1044
1020
  this.logWorkflow = logWorkflow;
1045
1021
  this.debug = debug;
1046
1022
  }
1023
+ handleBuildPipeline(req) {
1024
+ const pipelineList = [];
1025
+ const addedForeignLookups = new Map();
1026
+ const { query, sort, cursor, limit, stopLimit, pipeline } = req.body;
1027
+ try {
1028
+ if (Array.isArray(pipeline) && pipeline.length > 0) {
1029
+ pipeline.forEach((link) => {
1030
+ const { condition, referenceSpaceLabel, spaceReferenceId, spaceReferenceAs, sort: referenceSort, } = link;
1031
+ if (spaceReferenceId) {
1032
+ const lookupStage = {
1033
+ $lookup: {
1034
+ from: spaceReferenceId,
1035
+ let: {},
1036
+ pipeline: [],
1037
+ as: spaceReferenceAs || "linkedData",
1038
+ },
1039
+ };
1040
+ if (condition && condition.length > 0) {
1041
+ condition.forEach((cond) => {
1042
+ lookupStage.$lookup.let[`local_${cond.fromColumnId}`] = `$${cond.fromColumnId}`;
1043
+ });
1044
+ const matchStage = {
1045
+ $match: { $expr: { $and: [] } },
1046
+ };
1047
+ condition.forEach((cond) => {
1048
+ const conditionExpr = {};
1049
+ switch (cond.type) {
1050
+ case "=":
1051
+ conditionExpr.$eq = [
1052
+ `$${cond.toColumnId}`,
1053
+ `$$local_${cond.fromColumnId}`,
1054
+ ];
1055
+ break;
1056
+ case "!=":
1057
+ conditionExpr.$ne = [
1058
+ `$${cond.toColumnId}`,
1059
+ `$$local_${cond.fromColumnId}`,
1060
+ ];
1061
+ break;
1062
+ case ">":
1063
+ conditionExpr.$gt = [
1064
+ `$${cond.toColumnId}`,
1065
+ `$$local_${cond.fromColumnId}`,
1066
+ ];
1067
+ break;
1068
+ case "<":
1069
+ conditionExpr.$lt = [
1070
+ `$${cond.toColumnId}`,
1071
+ `$$local_${cond.fromColumnId}`,
1072
+ ];
1073
+ break;
1074
+ case "in":
1075
+ conditionExpr.$in = [
1076
+ `$${cond.toColumnId}`,
1077
+ `$$local_${cond.fromColumnId}`,
1078
+ ];
1079
+ break;
1080
+ case "!in":
1081
+ conditionExpr.$nin = [
1082
+ `$${cond.toColumnId}`,
1083
+ `$$local_${cond.fromColumnId}`,
1084
+ ];
1085
+ break;
1086
+ }
1087
+ if (Object.keys(conditionExpr).length > 0) {
1088
+ matchStage.$match.$expr.$and.push(conditionExpr);
1089
+ }
1090
+ });
1091
+ lookupStage.$lookup.pipeline.push(matchStage);
1092
+ }
1093
+ pipelineList.push(lookupStage);
1094
+ if (referenceSort && referenceSort.sortId) {
1095
+ pipelineList.push({
1096
+ $sort: {
1097
+ [`${spaceReferenceAs || "linkedData"}.${referenceSort.sortId}`]: referenceSort.type === "asc" ? 1 : -1,
1098
+ },
1099
+ });
1100
+ }
1101
+ pipelineList.push({
1102
+ $unwind: {
1103
+ path: `$${spaceReferenceAs || "linkedData"}`,
1104
+ preserveNullAndEmptyArrays: true,
1105
+ },
1106
+ });
1107
+ if (referenceSpaceLabel && referenceSpaceLabel.length > 0) {
1108
+ const addFieldsStage = { $addFields: {} };
1109
+ referenceSpaceLabel.forEach((field) => {
1110
+ addFieldsStage.$addFields[field] = `$${spaceReferenceAs || "linkedData"}.${field}`;
1111
+ });
1112
+ pipelineList.push(addFieldsStage);
1113
+ }
1114
+ const groupStage = {
1115
+ $group: {
1116
+ _id: "$_id",
1117
+ originalData: { $first: "$$ROOT" },
1118
+ },
1119
+ };
1120
+ referenceSpaceLabel === null || referenceSpaceLabel === void 0 ? void 0 : referenceSpaceLabel.forEach((field) => {
1121
+ groupStage.$group[field] = { $push: `$${field}` };
1122
+ });
1123
+ pipelineList.push(groupStage);
1124
+ // Merge back and remove 'originalData' and 'spaceReferenceAs'
1125
+ pipelineList.push({
1126
+ $replaceRoot: {
1127
+ newRoot: {
1128
+ $mergeObjects: ["$originalData", "$$ROOT"],
1129
+ },
1130
+ },
1131
+ });
1132
+ // Remove 'originalData' and 'spaceReferenceAs'
1133
+ pipelineList.push({
1134
+ $unset: ["originalData", spaceReferenceAs],
1135
+ });
1136
+ }
1137
+ });
1138
+ }
1139
+ if (query && query.length > 0) {
1140
+ query.forEach((q) => {
1141
+ if (q.foreign) {
1142
+ const alias = q.foreign.alias || q.foreign.localField;
1143
+ if (!addedForeignLookups.has(alias)) {
1144
+ pipelineList.push({
1145
+ $lookup: {
1146
+ from: q.foreign.collection,
1147
+ localField: q.foreign.localField,
1148
+ foreignField: q.foreign.foreignField,
1149
+ as: alias,
1150
+ },
1151
+ });
1152
+ addedForeignLookups.set(alias, true);
1153
+ }
1154
+ }
1155
+ });
1156
+ }
1157
+ if (query && query.length > 0) {
1158
+ const filter = handleParseQueryFilter(query);
1159
+ pipelineList.push({ $match: filter });
1160
+ }
1161
+ if (sort && sort.sortId) {
1162
+ pipelineList.push({
1163
+ $sort: { [sort.sortId]: sort.type === "asc" ? 1 : -1 },
1164
+ });
1165
+ }
1166
+ if (cursor) {
1167
+ pipelineList.push({ $skip: Number.parseInt(cursor) });
1168
+ }
1169
+ if (!stopLimit) {
1170
+ pipelineList.push({ $limit: limit || 10 });
1171
+ }
1172
+ // INFO : Remove Link Search
1173
+ const foreignAliases = Array.from(addedForeignLookups.keys());
1174
+ if (foreignAliases.length > 0) {
1175
+ pipelineList.push({
1176
+ $unset: [...foreignAliases],
1177
+ });
1178
+ }
1179
+ }
1180
+ catch (err) { }
1181
+ return pipelineList;
1182
+ }
1047
1183
  }
1048
1184
  exports.MongoWrapper = MongoWrapper;
@@ -15,9 +15,38 @@ export interface Query {
15
15
  value: any;
16
16
  queryId?: string;
17
17
  searchIds?: string[];
18
+ foreign?: {
19
+ collection: string;
20
+ localField: string;
21
+ foreignField: string;
22
+ searchFields: string[];
23
+ alias?: string;
24
+ };
18
25
  orQuery?: boolean;
19
26
  orQueryGroupId?: string;
20
27
  }
28
+ interface PipelineCondition {
29
+ type: "=" | "!=" | ">" | "<" | "><" | "in" | "!in";
30
+ fromColumnId: string;
31
+ toColumnId: string;
32
+ }
33
+ /**
34
+ * PipeLine
35
+ *
36
+ * Only mongoDB is supported
37
+ * - condition : Condition that is applied to the reference collection
38
+ * - referenceSpaceLabel : Label fields of the reference collection that we wants to show.
39
+ * - spaceReferenceId : Reference collection ID
40
+ * - spaceReferenceAs : Alias of the reference collection (any name can be given)
41
+ * - sort : Sort of the reference collection
42
+ */
43
+ export interface PipeLine {
44
+ condition: PipelineCondition[];
45
+ referenceSpaceLabel: string[];
46
+ spaceReferenceId: string;
47
+ spaceReferenceAs: string;
48
+ sort: Sort;
49
+ }
21
50
  /**
22
51
  * @SupportedAggregate
23
52
  * - sum
@@ -71,4 +100,5 @@ export declare const checkBaseConfig: (config: SecurityConfig, req: any) => bool
71
100
  * @returns
72
101
  */
73
102
  export declare const checkOpsConfig: (config: SecurityConfig, type: "read" | "create" | "update" | "delete", req: any, doc: any) => boolean;
103
+ export {};
74
104
  //# sourceMappingURL=QueryModel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueryModel.d.ts","sourceRoot":"","sources":["../../src/model/QueryModel.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,WAA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AChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE;QACP,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,EAAE;YACP,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,EAAE,OAAO,CAAC;SAChB,CAAC;KACH,EAAE,CAAC;CACL;AAED,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,WAAY,cAAc,OAAO,GAAG,YAmC/D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,WACjB,cAAc,QAChB,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,OACxC,GAAG,OACH,GAAG,YAyDT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,