@verdocs/js-sdk 3.6.8 → 3.6.10
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/Templates/Actions.d.ts +26 -0
- package/Templates/Actions.js +104 -0
- package/Templates/Stars.d.ts +2 -2
- package/Templates/Templates.d.ts +1 -0
- package/Templates/index.d.ts +1 -0
- package/Templates/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ITemplate, ITemplateSummaryEntry } from './Types';
|
|
2
|
+
import { TSession } from '../Sessions/Types';
|
|
3
|
+
export declare enum TemplateSenderTypes {
|
|
4
|
+
CREATOR = "creator",
|
|
5
|
+
ORGANIZATION_MEMBER = "organization_member",
|
|
6
|
+
ORGANIZATION_MEMBER_AS_CREATOR = "organization_member_as_creator",
|
|
7
|
+
EVERYONE = "everyone",
|
|
8
|
+
EVERYONE_AS_CREATOR = "everyone_as_creator"
|
|
9
|
+
}
|
|
10
|
+
export declare enum TemplatePermissions {
|
|
11
|
+
TEMPLATE_CREATOR_CREATE_PUBLIC = "template:creator:create:public",
|
|
12
|
+
TEMPLATE_CREATOR_CREATE_ORG = "template:creator:create:org",
|
|
13
|
+
TEMPLATE_CREATOR_CREATE_PERSONAL = "template:creator:create:personal",
|
|
14
|
+
TEMPLATE_CREATOR_DELETE = "template:creator:delete",
|
|
15
|
+
TEMPLATE_CREATOR_VISIBILITY = "template:creator:visibility",
|
|
16
|
+
TEMPLATE_MEMBER_READ = "template:member:read",
|
|
17
|
+
TEMPLATE_MEMBER_WRITE = "template:member:write",
|
|
18
|
+
TEMPLATE_MEMBER_DELETE = "template:member:delete",
|
|
19
|
+
TEMPLATE_MEMBER_VISIBILITY = "template:member:visibility"
|
|
20
|
+
}
|
|
21
|
+
export type TTemplateActions = 'create_personal' | 'create_org' | 'create_public' | 'read' | 'write' | 'delete' | 'change_visibility_personal' | 'change_visibility_org' | 'change_visibility_public';
|
|
22
|
+
export declare const canPerformTemplateAction: (session: TSession, action: TTemplateActions, template?: ITemplate | ITemplateSummaryEntry) => {
|
|
23
|
+
canPerform: boolean;
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
export declare const hasRequiredPermissions: (session: TSession, permissions: string[]) => boolean;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export var TemplateSenderTypes;
|
|
2
|
+
(function (TemplateSenderTypes) {
|
|
3
|
+
TemplateSenderTypes["CREATOR"] = "creator";
|
|
4
|
+
TemplateSenderTypes["ORGANIZATION_MEMBER"] = "organization_member";
|
|
5
|
+
TemplateSenderTypes["ORGANIZATION_MEMBER_AS_CREATOR"] = "organization_member_as_creator";
|
|
6
|
+
TemplateSenderTypes["EVERYONE"] = "everyone";
|
|
7
|
+
TemplateSenderTypes["EVERYONE_AS_CREATOR"] = "everyone_as_creator";
|
|
8
|
+
})(TemplateSenderTypes || (TemplateSenderTypes = {}));
|
|
9
|
+
export var TemplatePermissions;
|
|
10
|
+
(function (TemplatePermissions) {
|
|
11
|
+
TemplatePermissions["TEMPLATE_CREATOR_CREATE_PUBLIC"] = "template:creator:create:public";
|
|
12
|
+
TemplatePermissions["TEMPLATE_CREATOR_CREATE_ORG"] = "template:creator:create:org";
|
|
13
|
+
TemplatePermissions["TEMPLATE_CREATOR_CREATE_PERSONAL"] = "template:creator:create:personal";
|
|
14
|
+
TemplatePermissions["TEMPLATE_CREATOR_DELETE"] = "template:creator:delete";
|
|
15
|
+
TemplatePermissions["TEMPLATE_CREATOR_VISIBILITY"] = "template:creator:visibility";
|
|
16
|
+
TemplatePermissions["TEMPLATE_MEMBER_READ"] = "template:member:read";
|
|
17
|
+
TemplatePermissions["TEMPLATE_MEMBER_WRITE"] = "template:member:write";
|
|
18
|
+
TemplatePermissions["TEMPLATE_MEMBER_DELETE"] = "template:member:delete";
|
|
19
|
+
TemplatePermissions["TEMPLATE_MEMBER_VISIBILITY"] = "template:member:visibility";
|
|
20
|
+
})(TemplatePermissions || (TemplatePermissions = {}));
|
|
21
|
+
export var canPerformTemplateAction = function (session, action, template) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if (!template && !action.includes('create')) {
|
|
24
|
+
return { canPerform: false, message: 'Missing required template object' };
|
|
25
|
+
}
|
|
26
|
+
// We use BOGUS here to force the option-chain in things like template?.profile_id to NOT match profile?.profile_id because if both
|
|
27
|
+
// were undefined, they would actually match.
|
|
28
|
+
var profile_id = (session === null || session === void 0 ? void 0 : session.profile_id) || 'BOGUS';
|
|
29
|
+
var organization_id = (session === null || session === void 0 ? void 0 : session.organization_id) || 'BOGUS';
|
|
30
|
+
if (!profile_id) {
|
|
31
|
+
return { canPerform: false, message: 'Active session required' };
|
|
32
|
+
}
|
|
33
|
+
var isCreator = (template === null || template === void 0 ? void 0 : template.profile_id) === profile_id;
|
|
34
|
+
var isSameOrg = (template === null || template === void 0 ? void 0 : template.organization_id) === organization_id;
|
|
35
|
+
var isPersonal = (_a = template === null || template === void 0 ? void 0 : template.is_personal) !== null && _a !== void 0 ? _a : false;
|
|
36
|
+
var isPublic = (_b = template === null || template === void 0 ? void 0 : template.is_public) !== null && _b !== void 0 ? _b : false;
|
|
37
|
+
var permissionsRequired = [];
|
|
38
|
+
switch (action) {
|
|
39
|
+
case 'create_personal':
|
|
40
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_CREATE_PERSONAL);
|
|
41
|
+
break;
|
|
42
|
+
case 'create_org':
|
|
43
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_CREATE_ORG);
|
|
44
|
+
break;
|
|
45
|
+
case 'create_public':
|
|
46
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_CREATE_PUBLIC);
|
|
47
|
+
break;
|
|
48
|
+
case 'read':
|
|
49
|
+
if (!isCreator) {
|
|
50
|
+
if ((!isPersonal && isSameOrg) || !isPublic) {
|
|
51
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_MEMBER_READ);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case 'write':
|
|
56
|
+
if (!isCreator) {
|
|
57
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_MEMBER_READ);
|
|
58
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_MEMBER_WRITE);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case 'change_visibility_personal':
|
|
62
|
+
if (isCreator) {
|
|
63
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_CREATE_PERSONAL);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_MEMBER_VISIBILITY);
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 'change_visibility_org':
|
|
70
|
+
if (isCreator) {
|
|
71
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_CREATE_ORG);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_MEMBER_VISIBILITY);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case 'change_visibility_public':
|
|
78
|
+
if (isCreator) {
|
|
79
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_CREATE_PUBLIC);
|
|
80
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_VISIBILITY);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_MEMBER_VISIBILITY);
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case 'delete':
|
|
87
|
+
if (isCreator) {
|
|
88
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_CREATOR_DELETE);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
permissionsRequired.push(TemplatePermissions.TEMPLATE_MEMBER_DELETE);
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
return { canPerform: false, message: 'Action is not defined' };
|
|
96
|
+
}
|
|
97
|
+
if (hasRequiredPermissions(session, permissionsRequired)) {
|
|
98
|
+
return { canPerform: true, message: '' };
|
|
99
|
+
}
|
|
100
|
+
return { canPerform: false, message: "Insufficient access to perform '".concat(action, "'. Needed permissions: ").concat(permissionsRequired.toString()) };
|
|
101
|
+
};
|
|
102
|
+
export var hasRequiredPermissions = function (session, permissions) {
|
|
103
|
+
return permissions.every(function (perm) { return ((session === null || session === void 0 ? void 0 : session.permissions) || []).includes(perm); });
|
|
104
|
+
};
|
package/Templates/Stars.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IStar,
|
|
1
|
+
import { IStar, ITemplateSummaryEntry } from './Types';
|
|
2
2
|
import { VerdocsEndpoint } from '../VerdocsEndpoint';
|
|
3
3
|
/**
|
|
4
4
|
* Get the template stars for a template.
|
|
@@ -7,4 +7,4 @@ export declare const getStars: (endpoint: VerdocsEndpoint, templateId: string) =
|
|
|
7
7
|
/**
|
|
8
8
|
* Toggle the template star for a template.
|
|
9
9
|
*/
|
|
10
|
-
export declare const toggleStar: (endpoint: VerdocsEndpoint, templateId: string) => Promise<
|
|
10
|
+
export declare const toggleStar: (endpoint: VerdocsEndpoint, templateId: string) => Promise<ITemplateSummaryEntry>;
|
package/Templates/Templates.d.ts
CHANGED
package/Templates/index.d.ts
CHANGED
package/Templates/index.js
CHANGED