@openinc/parse-server-opendash 1.8.5 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/_init.js +1 -1
- package/dist/functions/getAdminConfig.js +1 -1
- package/dist/hooks/Alarm.js +1 -1
- package/dist/hooks/Dashboard.js +1 -1
- package/dist/hooks/Notification.js +82 -51
- package/dist/hooks/Push.d.ts +1 -0
- package/dist/hooks/Push.js +81 -0
- package/dist/hooks/Source.js +2 -2
- package/dist/hooks/SourceMeta.js +1 -1
- package/dist/hooks/Tenant.js +11 -11
- package/dist/hooks/_User.js +7 -7
- package/dist/hooks/_init.js +1 -1
- package/dist/index.js +7 -7
- package/dist/types/Push.d.ts +14 -0
- package/dist/types/Push.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +12 -12
- package/schema/Push.json +52 -0
package/dist/functions/_init.js
CHANGED
|
@@ -57,7 +57,7 @@ function init() {
|
|
|
57
57
|
case 1:
|
|
58
58
|
if (!(_i < fns_1.length)) return [3 /*break*/, 4];
|
|
59
59
|
name = fns_1[_i];
|
|
60
|
-
init_1 = require("./"
|
|
60
|
+
init_1 = require("./".concat(name)).init;
|
|
61
61
|
return [4 /*yield*/, init_1(name).catch(function (e) { return console.error(e); })];
|
|
62
62
|
case 2:
|
|
63
63
|
_a.sent();
|
|
@@ -108,7 +108,7 @@ function evaluateClassLevelPermission(userId, roles, permissions) {
|
|
|
108
108
|
}
|
|
109
109
|
for (var _i = 0, roles_1 = roles; _i < roles_1.length; _i++) {
|
|
110
110
|
var role = roles_1[_i];
|
|
111
|
-
if (permissions["role:"
|
|
111
|
+
if (permissions["role:".concat(role)]) {
|
|
112
112
|
return true;
|
|
113
113
|
}
|
|
114
114
|
}
|
package/dist/hooks/Alarm.js
CHANGED
|
@@ -80,7 +80,7 @@ function init(className) {
|
|
|
80
80
|
"od-session": (user === null || user === void 0 ? void 0 : user.getSessionToken()) || "",
|
|
81
81
|
};
|
|
82
82
|
body = JSON.stringify(__assign(__assign({}, object.toJSON()), { owner: object.get("user"), createdAt: undefined, updatedAt: undefined, ACL: undefined }));
|
|
83
|
-
return [4 /*yield*/, (0, node_fetch_1.default)(baseurl
|
|
83
|
+
return [4 /*yield*/, (0, node_fetch_1.default)("".concat(baseurl, "/api/alarmsV2/").concat(username), {
|
|
84
84
|
method: "POST",
|
|
85
85
|
headers: headers,
|
|
86
86
|
body: body,
|
package/dist/hooks/Dashboard.js
CHANGED
|
@@ -61,7 +61,7 @@ function init(className) {
|
|
|
61
61
|
widgetIds = object.get("widgets");
|
|
62
62
|
if (!(acl && Array.isArray(widgetIds) && widgetIds.length > 0)) return [3 /*break*/, 3];
|
|
63
63
|
widgets = widgetIds === null || widgetIds === void 0 ? void 0 : widgetIds.map(function (id) {
|
|
64
|
-
return new Parse.Object(__1.PREFIX
|
|
64
|
+
return new Parse.Object("".concat(__1.PREFIX, "Widget"), {
|
|
65
65
|
objectId: id,
|
|
66
66
|
});
|
|
67
67
|
});
|
|
@@ -57,67 +57,67 @@ function init(className) {
|
|
|
57
57
|
(0, __1.afterSaveHook)(className, function (_a) {
|
|
58
58
|
var object = _a.object, original = _a.original, user = _a.user;
|
|
59
59
|
return __awaiter(_this, void 0, void 0, function () {
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return __generator(this, function (_m) {
|
|
64
|
-
switch (_m.label) {
|
|
60
|
+
var icon, _b, title, description, subscriptions, _i, subscriptions_1, subscription, webpushSubs, _c, webpushSubs_1, subscription;
|
|
61
|
+
return __generator(this, function (_d) {
|
|
62
|
+
switch (_d.label) {
|
|
65
63
|
case 0:
|
|
66
|
-
if (!!object.get("isSent")) return [3 /*break*/,
|
|
67
|
-
|
|
64
|
+
if (!!object.get("isSent")) return [3 /*break*/, 14];
|
|
65
|
+
_b = object.get("iconPath");
|
|
66
|
+
if (_b) return [3 /*break*/, 2];
|
|
67
|
+
return [4 /*yield*/, (0, __1.getConfig)("WEB_PUSH_ICON")];
|
|
68
|
+
case 1:
|
|
69
|
+
_b = (_d.sent());
|
|
70
|
+
_d.label = 2;
|
|
71
|
+
case 2:
|
|
72
|
+
icon = _b;
|
|
73
|
+
title = object.get("title");
|
|
74
|
+
description = object.get("description");
|
|
75
|
+
return [4 /*yield*/, new Parse.Query("".concat(__1.PREFIX, "Push"))
|
|
68
76
|
.equalTo("user", object.get("user"))
|
|
77
|
+
.limit(100000)
|
|
69
78
|
.find({
|
|
70
79
|
useMasterKey: true,
|
|
71
80
|
})];
|
|
72
|
-
case 1:
|
|
73
|
-
subscriptions = _m.sent();
|
|
74
|
-
console.log("[@openinc/parse-server-opendash][Notification]", "notification=\"" + (object === null || object === void 0 ? void 0 : object.id) + "\"", "user=\"" + ((_k = object === null || object === void 0 ? void 0 : object.get("user")) === null || _k === void 0 ? void 0 : _k.id) + "\"", "type=\"webpush\"", "subscriptions=\"" + subscriptions.map(function (s) { return s.id; }).join(", ") + "\"");
|
|
75
|
-
_i = 0, subscriptions_1 = subscriptions;
|
|
76
|
-
_m.label = 2;
|
|
77
|
-
case 2:
|
|
78
|
-
if (!(_i < subscriptions_1.length)) return [3 /*break*/, 9];
|
|
79
|
-
subscription = subscriptions_1[_i];
|
|
80
|
-
_m.label = 3;
|
|
81
81
|
case 3:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
_d =
|
|
85
|
-
_f = (_e = JSON).stringify;
|
|
86
|
-
_h = {
|
|
87
|
-
type: "notification",
|
|
88
|
-
title: object.get("title")
|
|
89
|
-
};
|
|
90
|
-
_j = {
|
|
91
|
-
body: object.get("description"),
|
|
92
|
-
data: object.get("data")
|
|
93
|
-
};
|
|
94
|
-
_g = object.get("iconPath");
|
|
95
|
-
if (_g) return [3 /*break*/, 5];
|
|
96
|
-
return [4 /*yield*/, (0, __1.getConfig)("WEB_PUSH_ICON")];
|
|
82
|
+
subscriptions = _d.sent();
|
|
83
|
+
_i = 0, subscriptions_1 = subscriptions;
|
|
84
|
+
_d.label = 4;
|
|
97
85
|
case 4:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}]))];
|
|
86
|
+
if (!(_i < subscriptions_1.length)) return [3 /*break*/, 7];
|
|
87
|
+
subscription = subscriptions_1[_i];
|
|
88
|
+
if (!(subscription.get("type") === "web")) return [3 /*break*/, 6];
|
|
89
|
+
return [4 /*yield*/, sendWebPush(subscription.get("data"), object.id, title, description, icon, object.get("data"))];
|
|
90
|
+
case 5:
|
|
91
|
+
_d.sent();
|
|
92
|
+
_d.label = 6;
|
|
106
93
|
case 6:
|
|
107
|
-
_m.sent();
|
|
108
|
-
return [3 /*break*/, 8];
|
|
109
|
-
case 7:
|
|
110
|
-
error_1 = _m.sent();
|
|
111
|
-
console.error("[@openinc/parse-server-opendash][Notification]", "notification=\"" + (object === null || object === void 0 ? void 0 : object.id) + "\"", "user=\"" + ((_l = object === null || object === void 0 ? void 0 : object.get("user")) === null || _l === void 0 ? void 0 : _l.id) + "\"", "type=\"webpush\"", "subscription=\"" + (subscription === null || subscription === void 0 ? void 0 : subscription.id) + "\"", "error=\n", error_1);
|
|
112
|
-
return [3 /*break*/, 8];
|
|
113
|
-
case 8:
|
|
114
94
|
_i++;
|
|
115
|
-
return [3 /*break*/,
|
|
116
|
-
case
|
|
95
|
+
return [3 /*break*/, 4];
|
|
96
|
+
case 7: return [4 /*yield*/, new Parse.Query("".concat(__1.PREFIX, "WebPush"))
|
|
97
|
+
.equalTo("user", object.get("user"))
|
|
98
|
+
.limit(100000)
|
|
99
|
+
.find({
|
|
100
|
+
useMasterKey: true,
|
|
101
|
+
})];
|
|
102
|
+
case 8:
|
|
103
|
+
webpushSubs = _d.sent();
|
|
104
|
+
_c = 0, webpushSubs_1 = webpushSubs;
|
|
105
|
+
_d.label = 9;
|
|
106
|
+
case 9:
|
|
107
|
+
if (!(_c < webpushSubs_1.length)) return [3 /*break*/, 12];
|
|
108
|
+
subscription = webpushSubs_1[_c];
|
|
109
|
+
return [4 /*yield*/, sendWebPush(subscription.get("subscription"), object.id, title, description, icon, object.get("data"))];
|
|
117
110
|
case 10:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
case 11:
|
|
111
|
+
_d.sent();
|
|
112
|
+
_d.label = 11;
|
|
113
|
+
case 11:
|
|
114
|
+
_c++;
|
|
115
|
+
return [3 /*break*/, 9];
|
|
116
|
+
case 12: return [4 /*yield*/, object.save({ isSent: true }, { useMasterKey: true })];
|
|
117
|
+
case 13:
|
|
118
|
+
_d.sent();
|
|
119
|
+
_d.label = 14;
|
|
120
|
+
case 14: return [2 /*return*/];
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
});
|
|
@@ -127,3 +127,34 @@ function init(className) {
|
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
exports.init = init;
|
|
130
|
+
function sendWebPush(subscription, id, title, description, icon, data) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
var error_1;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
_a.trys.push([0, 2, , 3]);
|
|
137
|
+
console.log("[@openinc/parse-server-opendash][Notification]", "notification=\"".concat(id, "\""), "type=\"web\"", "subscription=\"".concat(subscription === null || subscription === void 0 ? void 0 : subscription.id, "\""));
|
|
138
|
+
return [4 /*yield*/, web_push_1.default.sendNotification(subscription, JSON.stringify({
|
|
139
|
+
type: "notification",
|
|
140
|
+
title: title,
|
|
141
|
+
options: {
|
|
142
|
+
body: description,
|
|
143
|
+
data: data,
|
|
144
|
+
icon: icon,
|
|
145
|
+
},
|
|
146
|
+
}), {
|
|
147
|
+
TTL: 0,
|
|
148
|
+
})];
|
|
149
|
+
case 1:
|
|
150
|
+
_a.sent();
|
|
151
|
+
return [3 /*break*/, 3];
|
|
152
|
+
case 2:
|
|
153
|
+
error_1 = _a.sent();
|
|
154
|
+
console.error("[@openinc/parse-server-opendash][Notification]", "notification=\"".concat(id, "\""), "type=\"web\"", "subscription=\"".concat(subscription === null || subscription === void 0 ? void 0 : subscription.id, "\""), "error=\n", error_1);
|
|
155
|
+
return [3 /*break*/, 3];
|
|
156
|
+
case 3: return [2 /*return*/];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(className: string): Promise<void>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.init = void 0;
|
|
40
|
+
var __1 = require("..");
|
|
41
|
+
function init(className) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var _this = this;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
(0, __1.beforeSaveHook)(className, function (request) { return __awaiter(_this, void 0, void 0, function () {
|
|
46
|
+
var object, installationId, user;
|
|
47
|
+
var _a;
|
|
48
|
+
return __generator(this, function (_b) {
|
|
49
|
+
object = request.object, installationId = request.installationId, user = request.user;
|
|
50
|
+
(0, __1.defaultHandler)(request);
|
|
51
|
+
if (!user && !object.get("user")) {
|
|
52
|
+
throw new Parse.Error(142, "User Missing");
|
|
53
|
+
}
|
|
54
|
+
if (user && object.get("user") && user.id !== object.get("user").id) {
|
|
55
|
+
throw new Parse.Error(142, "Invalid User");
|
|
56
|
+
}
|
|
57
|
+
if (user) {
|
|
58
|
+
object.set("user", user);
|
|
59
|
+
}
|
|
60
|
+
if (installationId) {
|
|
61
|
+
object.set("installationId", installationId);
|
|
62
|
+
}
|
|
63
|
+
object.setACL(new Parse.ACL((_a = {},
|
|
64
|
+
_a[object.get("user").id] = { read: true, write: true },
|
|
65
|
+
_a)));
|
|
66
|
+
return [2 /*return*/];
|
|
67
|
+
});
|
|
68
|
+
}); });
|
|
69
|
+
(0, __1.afterSaveHook)(className, function (_a) {
|
|
70
|
+
var object = _a.object, original = _a.original, user = _a.user;
|
|
71
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
72
|
+
return __generator(this, function (_b) {
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.init = init;
|
package/dist/hooks/Source.js
CHANGED
|
@@ -57,8 +57,8 @@ function init(className) {
|
|
|
57
57
|
acl.setRoleWriteAccess("od-admin", true);
|
|
58
58
|
tenant = object.get("tenant");
|
|
59
59
|
if (tenant === null || tenant === void 0 ? void 0 : tenant.id) {
|
|
60
|
-
acl.setRoleReadAccess("od-tenant-admin-"
|
|
61
|
-
acl.setRoleWriteAccess("od-tenant-admin-"
|
|
60
|
+
acl.setRoleReadAccess("od-tenant-admin-".concat(tenant === null || tenant === void 0 ? void 0 : tenant.id), true);
|
|
61
|
+
acl.setRoleWriteAccess("od-tenant-admin-".concat(tenant === null || tenant === void 0 ? void 0 : tenant.id), true);
|
|
62
62
|
}
|
|
63
63
|
object.setACL(acl);
|
|
64
64
|
// ACL end
|
package/dist/hooks/SourceMeta.js
CHANGED
|
@@ -58,7 +58,7 @@ function init(className) {
|
|
|
58
58
|
switch (_c.label) {
|
|
59
59
|
case 0:
|
|
60
60
|
_c.trys.push([0, 9, , 10]);
|
|
61
|
-
return [4 /*yield*/, new Parse.Query(__1.PREFIX
|
|
61
|
+
return [4 /*yield*/, new Parse.Query("".concat(__1.PREFIX, "Source"))
|
|
62
62
|
.equalTo("meta", object)
|
|
63
63
|
.find({ useMasterKey: true })];
|
|
64
64
|
case 1:
|
package/dist/hooks/Tenant.js
CHANGED
|
@@ -52,10 +52,10 @@ function init(className) {
|
|
|
52
52
|
(0, __1.defaultHandler)(request);
|
|
53
53
|
if (!object.id) return [3 /*break*/, 5];
|
|
54
54
|
object.setACL(new Parse.ACL((_a = {},
|
|
55
|
-
_a["role:od-tenant-user-"
|
|
55
|
+
_a["role:od-tenant-user-".concat(object.id)] = {
|
|
56
56
|
read: true,
|
|
57
57
|
},
|
|
58
|
-
_a["role:od-tenant-admin-"
|
|
58
|
+
_a["role:od-tenant-admin-".concat(object.id)] = {
|
|
59
59
|
read: true,
|
|
60
60
|
write: true,
|
|
61
61
|
},
|
|
@@ -65,7 +65,7 @@ function init(className) {
|
|
|
65
65
|
},
|
|
66
66
|
_a)));
|
|
67
67
|
if (!!object.get("meta")) return [3 /*break*/, 2];
|
|
68
|
-
meta = new Parse.Object(__1.PREFIX
|
|
68
|
+
meta = new Parse.Object("".concat(__1.PREFIX, "TenantMeta"), {
|
|
69
69
|
tenant: object,
|
|
70
70
|
});
|
|
71
71
|
return [4 /*yield*/, meta.save(null, { useMasterKey: true, cascadeSave: false })];
|
|
@@ -73,26 +73,26 @@ function init(className) {
|
|
|
73
73
|
_c.sent();
|
|
74
74
|
object.set("meta", meta);
|
|
75
75
|
_c.label = 2;
|
|
76
|
-
case 2: return [4 /*yield*/, new Parse.Query(__1.PREFIX
|
|
76
|
+
case 2: return [4 /*yield*/, new Parse.Query("".concat(__1.PREFIX, "Source"))
|
|
77
77
|
.equalTo("tag", "tenant-root-source")
|
|
78
78
|
.first({ useMasterKey: true })];
|
|
79
79
|
case 3:
|
|
80
80
|
rootSource = _c.sent();
|
|
81
81
|
sourceACL = new Parse.ACL((_b = {},
|
|
82
|
-
_b["role:od-tenant-user-"
|
|
82
|
+
_b["role:od-tenant-user-".concat(object.id)] = {
|
|
83
83
|
read: true,
|
|
84
84
|
},
|
|
85
85
|
_b));
|
|
86
86
|
dataSource = object.get("dataSource");
|
|
87
87
|
if (!dataSource) {
|
|
88
|
-
dataSource = new Parse.Object(__1.PREFIX
|
|
88
|
+
dataSource = new Parse.Object("".concat(__1.PREFIX, "Source"));
|
|
89
89
|
}
|
|
90
90
|
dataSource.setACL(sourceACL);
|
|
91
91
|
if (rootSource) {
|
|
92
92
|
dataSource.set("parent", rootSource);
|
|
93
93
|
}
|
|
94
94
|
dataSource.set("name", object.get("label"));
|
|
95
|
-
dataSource.set("tag", "tenant-data-"
|
|
95
|
+
dataSource.set("tag", "tenant-data-".concat(object.id));
|
|
96
96
|
return [4 /*yield*/, dataSource.save(null, { useMasterKey: true })];
|
|
97
97
|
case 4:
|
|
98
98
|
_c.sent();
|
|
@@ -109,15 +109,15 @@ function init(className) {
|
|
|
109
109
|
var _b;
|
|
110
110
|
return __generator(this, function (_c) {
|
|
111
111
|
switch (_c.label) {
|
|
112
|
-
case 0: return [4 /*yield*/, (0, __1.ensureRole)("od-tenant-admin-"
|
|
113
|
-
label: object.get("label")
|
|
112
|
+
case 0: return [4 /*yield*/, (0, __1.ensureRole)("od-tenant-admin-".concat(object.id), {
|
|
113
|
+
label: "".concat(object.get("label"), " (Admin)"),
|
|
114
114
|
})];
|
|
115
115
|
case 1:
|
|
116
116
|
_c.sent();
|
|
117
|
-
return [4 /*yield*/, (0, __1.ensureRole)("od-tenant-user-"
|
|
117
|
+
return [4 /*yield*/, (0, __1.ensureRole)("od-tenant-user-".concat(object.id), {
|
|
118
118
|
label: object.get("label"),
|
|
119
119
|
acl: new Parse.ACL((_b = {},
|
|
120
|
-
_b["role:od-tenant-user-"
|
|
120
|
+
_b["role:od-tenant-user-".concat(object.id)] = {
|
|
121
121
|
read: true,
|
|
122
122
|
},
|
|
123
123
|
_b)),
|
package/dist/hooks/_User.js
CHANGED
|
@@ -75,7 +75,7 @@ function init() {
|
|
|
75
75
|
!!user.get("emailVerified") &&
|
|
76
76
|
!user.get("tenantVerified"))) return [3 /*break*/, 4];
|
|
77
77
|
email = user.get("email");
|
|
78
|
-
return [4 /*yield*/, new Parse.Query(__1.PREFIX
|
|
78
|
+
return [4 /*yield*/, new Parse.Query("".concat(__1.PREFIX, "TenantTrustedDomain"))
|
|
79
79
|
.equalTo("tenant", tenant)
|
|
80
80
|
.find({ useMasterKey: true })];
|
|
81
81
|
case 3:
|
|
@@ -103,8 +103,8 @@ function init() {
|
|
|
103
103
|
request.context.tenantChanged = true;
|
|
104
104
|
}
|
|
105
105
|
user.setACL(new Parse.ACL(__assign(__assign(__assign(__assign({}, (tenantId && (_a = {},
|
|
106
|
-
_a["role:od-tenant-user-"
|
|
107
|
-
_a["role:od-tenant-admin-"
|
|
106
|
+
_a["role:od-tenant-user-".concat(tenantId)] = { read: true },
|
|
107
|
+
_a["role:od-tenant-admin-".concat(tenantId)] = { read: true, write: true },
|
|
108
108
|
_a))), (user.get("tenantGlobal") && {
|
|
109
109
|
"role:od-tenant-global-visible": { read: true },
|
|
110
110
|
})), (user.id && (_b = {},
|
|
@@ -160,19 +160,19 @@ function init() {
|
|
|
160
160
|
case 7:
|
|
161
161
|
_d.sent();
|
|
162
162
|
if (!tenantId) return [3 /*break*/, 10];
|
|
163
|
-
return [4 /*yield*/, userRole(object, "od-tenant-user-"
|
|
163
|
+
return [4 /*yield*/, userRole(object, "od-tenant-user-".concat(tenantId), true)];
|
|
164
164
|
case 8:
|
|
165
165
|
_d.sent();
|
|
166
|
-
return [4 /*yield*/, userRole(object, "od-tenant-admin-"
|
|
166
|
+
return [4 /*yield*/, userRole(object, "od-tenant-admin-".concat(tenantId), isAdmin)];
|
|
167
167
|
case 9:
|
|
168
168
|
_d.sent();
|
|
169
169
|
_d.label = 10;
|
|
170
170
|
case 10:
|
|
171
171
|
if (!(wasTenant && tenantId !== prevTenantId)) return [3 /*break*/, 13];
|
|
172
|
-
return [4 /*yield*/, userRole(object, "od-tenant-user-"
|
|
172
|
+
return [4 /*yield*/, userRole(object, "od-tenant-user-".concat(prevTenantId), false)];
|
|
173
173
|
case 11:
|
|
174
174
|
_d.sent();
|
|
175
|
-
return [4 /*yield*/, userRole(object, "od-tenant-admin-"
|
|
175
|
+
return [4 /*yield*/, userRole(object, "od-tenant-admin-".concat(prevTenantId), false)];
|
|
176
176
|
case 12:
|
|
177
177
|
_d.sent();
|
|
178
178
|
_d.label = 13;
|
package/dist/hooks/_init.js
CHANGED
|
@@ -70,7 +70,7 @@ function init() {
|
|
|
70
70
|
case 1:
|
|
71
71
|
if (!(_i < classNames_1.length)) return [3 /*break*/, 4];
|
|
72
72
|
name = classNames_1[_i];
|
|
73
|
-
init_1 = require("./"
|
|
73
|
+
init_1 = require("./".concat(name)).init;
|
|
74
74
|
return [4 /*yield*/, init_1(__1.PREFIX + name).catch(function (e) { return console.error(e); })];
|
|
75
75
|
case 2:
|
|
76
76
|
_a.sent();
|
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function init(cfg) {
|
|
|
57
57
|
case 0:
|
|
58
58
|
try {
|
|
59
59
|
pkg = require("../package.json");
|
|
60
|
-
console.log("["
|
|
60
|
+
console.log("[".concat(pkg.name, "] init (v").concat(pkg.version, ")"));
|
|
61
61
|
}
|
|
62
62
|
catch (error) { }
|
|
63
63
|
return [4 /*yield*/, Parse.Config.get()];
|
|
@@ -187,7 +187,7 @@ function hasPermission(sessionToken, key) {
|
|
|
187
187
|
var result;
|
|
188
188
|
return __generator(this, function (_a) {
|
|
189
189
|
switch (_a.label) {
|
|
190
|
-
case 0: return [4 /*yield*/, new Parse.Query(exports.PREFIX
|
|
190
|
+
case 0: return [4 /*yield*/, new Parse.Query("".concat(exports.PREFIX, "Permission"))
|
|
191
191
|
.equalTo("key", key)
|
|
192
192
|
.first({ sessionToken: sessionToken })];
|
|
193
193
|
case 1:
|
|
@@ -232,7 +232,7 @@ function getConfig(key) {
|
|
|
232
232
|
var result, value;
|
|
233
233
|
return __generator(this, function (_a) {
|
|
234
234
|
switch (_a.label) {
|
|
235
|
-
case 0: return [4 /*yield*/, new Parse.Query(exports.PREFIX
|
|
235
|
+
case 0: return [4 /*yield*/, new Parse.Query("".concat(exports.PREFIX, "Config"))
|
|
236
236
|
.equalTo("key", key)
|
|
237
237
|
.first({
|
|
238
238
|
useMasterKey: true,
|
|
@@ -286,7 +286,7 @@ function ensureRole(name, options) {
|
|
|
286
286
|
label = (options === null || options === void 0 ? void 0 : options.label) || undefined;
|
|
287
287
|
acl = (options === null || options === void 0 ? void 0 : options.acl) || new Parse.ACL();
|
|
288
288
|
childRoles = (options === null || options === void 0 ? void 0 : options.childRoles) || undefined;
|
|
289
|
-
console.log("[@openinc/parse-server-opendash] ensureRole("
|
|
289
|
+
console.log("[@openinc/parse-server-opendash] ensureRole(".concat(name, ")"), JSON.stringify({ label: label, acl: acl, childRoles: childRoles }, null, 2));
|
|
290
290
|
return [4 /*yield*/, new Parse.Query(Parse.Role)
|
|
291
291
|
.equalTo("name", name)
|
|
292
292
|
.first({ useMasterKey: true })];
|
|
@@ -367,7 +367,7 @@ function immutableField(request, fieldName, permissionName) {
|
|
|
367
367
|
if ((0, fast_deep_equal_1.default)(previousValue, nextValue)) {
|
|
368
368
|
return [2 /*return*/];
|
|
369
369
|
}
|
|
370
|
-
return [4 /*yield*/, requirePermission(request, permissionName, "You are not allowed to edit the '"
|
|
370
|
+
return [4 /*yield*/, requirePermission(request, permissionName, "You are not allowed to edit the '".concat(fieldName, "' field."))];
|
|
371
371
|
case 1:
|
|
372
372
|
_a.sent();
|
|
373
373
|
return [2 /*return*/];
|
|
@@ -385,7 +385,7 @@ function defaultHandler(request) {
|
|
|
385
385
|
case 0:
|
|
386
386
|
className = request.object.className;
|
|
387
387
|
if (request.master) {
|
|
388
|
-
console.log("[@openinc/parse-server-opendash] Skipping default beforeSave() handler of "
|
|
388
|
+
console.log("[@openinc/parse-server-opendash] Skipping default beforeSave() handler of ".concat(className, " for masterkey"));
|
|
389
389
|
return [2 /*return*/];
|
|
390
390
|
}
|
|
391
391
|
if (!request.user) {
|
|
@@ -393,7 +393,7 @@ function defaultHandler(request) {
|
|
|
393
393
|
}
|
|
394
394
|
currentSchema = schema[className];
|
|
395
395
|
if (!currentSchema) {
|
|
396
|
-
console.warn("[@openinc/parse-server-opendash] Skipping default beforeSave() handler, no schema found for "
|
|
396
|
+
console.warn("[@openinc/parse-server-opendash] Skipping default beforeSave() handler, no schema found for ".concat(className));
|
|
397
397
|
return [2 /*return*/];
|
|
398
398
|
}
|
|
399
399
|
userField = !!((_a = currentSchema === null || currentSchema === void 0 ? void 0 : currentSchema.fields) === null || _a === void 0 ? void 0 : _a.user);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="parse" />
|
|
2
|
+
import { _User } from "./_User";
|
|
3
|
+
export interface PushAttributes {
|
|
4
|
+
id: string;
|
|
5
|
+
objectId: string;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
user: _User;
|
|
9
|
+
label: string;
|
|
10
|
+
type: string;
|
|
11
|
+
installationId: string;
|
|
12
|
+
data: any;
|
|
13
|
+
}
|
|
14
|
+
export declare type Push = Parse.Object<PushAttributes>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { NavigationGroup, NavigationGroupAttributes } from "./NavigationGroup";
|
|
|
13
13
|
export { NavigationItem, NavigationItemAttributes } from "./NavigationItem";
|
|
14
14
|
export { Notification, NotificationAttributes } from "./Notification";
|
|
15
15
|
export { Permission, PermissionAttributes } from "./Permission";
|
|
16
|
+
export { Push, PushAttributes } from "./Push";
|
|
16
17
|
export { Report, ReportAttributes } from "./Report";
|
|
17
18
|
export { Share, ShareAttributes } from "./Share";
|
|
18
19
|
export { Source, SourceAttributes } from "./Source";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openinc/parse-server-opendash",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Parse Server Cloud Code for open.DASH",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"parse",
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"schema-ts": "parse-server-schema typescript --prefix OD3_ --global-sdk --no-class ./src/types"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@openinc/parse-server-schema": "^1.
|
|
23
|
-
"fast-deep-equal": "^3.
|
|
24
|
-
"jsonwebtoken": "^8.
|
|
25
|
-
"node-fetch": "^2.
|
|
26
|
-
"web-push": "^3.
|
|
22
|
+
"@openinc/parse-server-schema": "^1.0.0",
|
|
23
|
+
"fast-deep-equal": "^3.0.0",
|
|
24
|
+
"jsonwebtoken": "^8.0.0",
|
|
25
|
+
"node-fetch": "^2.0.0",
|
|
26
|
+
"web-push": "^3.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/jsonwebtoken": "^8.
|
|
30
|
-
"@types/node": "^
|
|
31
|
-
"@types/node-fetch": "^2.
|
|
32
|
-
"@types/parse": "^2.
|
|
33
|
-
"@types/web-push": "^3.
|
|
34
|
-
"typescript": "^4.
|
|
29
|
+
"@types/jsonwebtoken": "^8.0.0",
|
|
30
|
+
"@types/node": "^16.0.0",
|
|
31
|
+
"@types/node-fetch": "^2.0.0",
|
|
32
|
+
"@types/parse": "^2.0.0",
|
|
33
|
+
"@types/web-push": "^3.0.0",
|
|
34
|
+
"typescript": "^4.0.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/schema/Push.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"fields": {
|
|
3
|
+
"user": {
|
|
4
|
+
"type": "Pointer",
|
|
5
|
+
"targetClass": "_User",
|
|
6
|
+
"required": true
|
|
7
|
+
},
|
|
8
|
+
"label": {
|
|
9
|
+
"type": "String",
|
|
10
|
+
"required": true,
|
|
11
|
+
"defaultValue": ""
|
|
12
|
+
},
|
|
13
|
+
"type": {
|
|
14
|
+
"type": "String",
|
|
15
|
+
"required": true,
|
|
16
|
+
"defaultValue": "invalid"
|
|
17
|
+
},
|
|
18
|
+
"installationId": {
|
|
19
|
+
"type": "String",
|
|
20
|
+
"required": true,
|
|
21
|
+
"defaultValue": ""
|
|
22
|
+
},
|
|
23
|
+
"data": {
|
|
24
|
+
"type": "Object",
|
|
25
|
+
"required": true
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"classLevelPermissions": {
|
|
29
|
+
"find": {
|
|
30
|
+
"requiresAuthentication": true
|
|
31
|
+
},
|
|
32
|
+
"count": {
|
|
33
|
+
"requiresAuthentication": true
|
|
34
|
+
},
|
|
35
|
+
"get": {
|
|
36
|
+
"requiresAuthentication": true
|
|
37
|
+
},
|
|
38
|
+
"create": {
|
|
39
|
+
"requiresAuthentication": true
|
|
40
|
+
},
|
|
41
|
+
"update": {
|
|
42
|
+
"requiresAuthentication": true
|
|
43
|
+
},
|
|
44
|
+
"delete": {
|
|
45
|
+
"requiresAuthentication": true
|
|
46
|
+
},
|
|
47
|
+
"addField": {},
|
|
48
|
+
"protectedFields": {
|
|
49
|
+
"*": []
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|