@cravery/core 0.0.12 → 0.0.13
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/lib/api.d.ts +4 -2
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/api.js +17 -7
- package/dist/lib/api.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/api.ts +23 -10
package/dist/lib/api.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ declare class CallableBuilder<T> {
|
|
|
5
5
|
private requiresAuth;
|
|
6
6
|
private requiresAdmin;
|
|
7
7
|
private requiresModerator;
|
|
8
|
+
private requiresTranslator;
|
|
8
9
|
private options;
|
|
9
10
|
constructor(schema: z.ZodSchema<T>);
|
|
10
|
-
withOptions(options: CallableOptions): this;
|
|
11
|
-
requireUser(): this;
|
|
12
11
|
requireAdmin(): this;
|
|
12
|
+
requireUser(): this;
|
|
13
13
|
requireModerator(): this;
|
|
14
|
+
requireTranslator(): this;
|
|
15
|
+
withOptions(options: CallableOptions): this;
|
|
14
16
|
handle<R>(handler: (data: T, request: CallableRequest) => Promise<R>): import("firebase-functions/v2/https").CallableFunction<any, Promise<R>, unknown>;
|
|
15
17
|
}
|
|
16
18
|
export declare const callable: <T>(schema: z.ZodSchema<T>) => CallableBuilder<T>;
|
package/dist/lib/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,eAAe,EAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAqB3B,cAAM,eAAe,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EACf,eAAe,EAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAqB3B,cAAM,eAAe,CAAC,CAAC;IAOT,OAAO,CAAC,MAAM;IAN1B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,OAAO,CAAoC;gBAE/B,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAE1C,YAAY;IAMZ,WAAW;IAKX,gBAAgB;IAMhB,iBAAiB;IAMjB,WAAW,CAAC,OAAO,EAAE,eAAe;IAKpC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC;CAmCrE;AAED,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,uBACrB,CAAC"}
|
package/dist/lib/api.js
CHANGED
|
@@ -20,24 +20,30 @@ class CallableBuilder {
|
|
|
20
20
|
this.requiresAuth = false;
|
|
21
21
|
this.requiresAdmin = false;
|
|
22
22
|
this.requiresModerator = false;
|
|
23
|
+
this.requiresTranslator = false;
|
|
23
24
|
this.options = DEFAULT_OPTIONS;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
this.
|
|
26
|
+
requireAdmin() {
|
|
27
|
+
this.requiresAuth = true;
|
|
28
|
+
this.requiresAdmin = true;
|
|
27
29
|
return this;
|
|
28
30
|
}
|
|
29
31
|
requireUser() {
|
|
30
32
|
this.requiresAuth = true;
|
|
31
33
|
return this;
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
requireModerator() {
|
|
34
36
|
this.requiresAuth = true;
|
|
35
|
-
this.
|
|
37
|
+
this.requiresModerator = true;
|
|
36
38
|
return this;
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
requireTranslator() {
|
|
39
41
|
this.requiresAuth = true;
|
|
40
|
-
this.
|
|
42
|
+
this.requiresTranslator = true;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
withOptions(options) {
|
|
46
|
+
this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
|
|
41
47
|
return this;
|
|
42
48
|
}
|
|
43
49
|
handle(handler) {
|
|
@@ -50,9 +56,13 @@ class CallableBuilder {
|
|
|
50
56
|
if (this.requiresAdmin && !(await (0, iam_1.isAdmin)(uid))) {
|
|
51
57
|
throw new https_1.HttpsError("permission-denied", "Admin access required");
|
|
52
58
|
}
|
|
53
|
-
if (this.requiresModerator && !(await (0, iam_1.
|
|
59
|
+
else if (this.requiresModerator && !(await (0, iam_1.isModeratorOrAbove)(uid))) {
|
|
54
60
|
throw new https_1.HttpsError("permission-denied", "Moderator access required");
|
|
55
61
|
}
|
|
62
|
+
else if (this.requiresTranslator &&
|
|
63
|
+
!(await (0, iam_1.isTranslatorOrAbove)(uid))) {
|
|
64
|
+
throw new https_1.HttpsError("permission-denied", "Translator access required");
|
|
65
|
+
}
|
|
56
66
|
}
|
|
57
67
|
try {
|
|
58
68
|
const data = this.schema.parse(request.data);
|
package/dist/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":";;;AAAA,uDAKqC;AACrC,mCAA2B;AAC3B,+
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":";;;AAAA,uDAKqC;AACrC,mCAA2B;AAC3B,+BAAyE;AAEzE,MAAM,eAAe,GAAoB,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;AAE/E,MAAM,WAAW,GAAG,CAAC,KAAc,EAAS,EAAE;IAC5C,IAAI,KAAK,YAAY,UAAC,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,IA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CACpD,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AADjB,QAAA,QAAQ,YACS"}
|
package/package.json
CHANGED
package/src/lib/api.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
CallableOptions,
|
|
6
6
|
} from "firebase-functions/v2/https";
|
|
7
7
|
import { z } from "genkit";
|
|
8
|
-
import { isAdmin,
|
|
8
|
+
import { isAdmin, isModeratorOrAbove, isTranslatorOrAbove } from "./iam";
|
|
9
9
|
|
|
10
10
|
const DEFAULT_OPTIONS: CallableOptions = { cors: true, enforceAppCheck: true };
|
|
11
11
|
|
|
@@ -29,12 +29,14 @@ class CallableBuilder<T> {
|
|
|
29
29
|
private requiresAuth = false;
|
|
30
30
|
private requiresAdmin = false;
|
|
31
31
|
private requiresModerator = false;
|
|
32
|
+
private requiresTranslator = false;
|
|
32
33
|
private options: CallableOptions = DEFAULT_OPTIONS;
|
|
33
34
|
|
|
34
35
|
constructor(private schema: z.ZodSchema<T>) {}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
this.
|
|
37
|
+
requireAdmin() {
|
|
38
|
+
this.requiresAuth = true;
|
|
39
|
+
this.requiresAdmin = true;
|
|
38
40
|
return this;
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -43,15 +45,20 @@ class CallableBuilder<T> {
|
|
|
43
45
|
return this;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
requireModerator() {
|
|
47
49
|
this.requiresAuth = true;
|
|
48
|
-
this.
|
|
50
|
+
this.requiresModerator = true;
|
|
49
51
|
return this;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
requireTranslator() {
|
|
53
55
|
this.requiresAuth = true;
|
|
54
|
-
this.
|
|
56
|
+
this.requiresTranslator = true;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
withOptions(options: CallableOptions) {
|
|
61
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
55
62
|
return this;
|
|
56
63
|
}
|
|
57
64
|
|
|
@@ -66,13 +73,19 @@ class CallableBuilder<T> {
|
|
|
66
73
|
|
|
67
74
|
if (this.requiresAdmin && !(await isAdmin(uid))) {
|
|
68
75
|
throw new HttpsError("permission-denied", "Admin access required");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (this.requiresModerator && !(await isModerator(uid))) {
|
|
76
|
+
} else if (this.requiresModerator && !(await isModeratorOrAbove(uid))) {
|
|
72
77
|
throw new HttpsError(
|
|
73
78
|
"permission-denied",
|
|
74
79
|
"Moderator access required",
|
|
75
80
|
);
|
|
81
|
+
} else if (
|
|
82
|
+
this.requiresTranslator &&
|
|
83
|
+
!(await isTranslatorOrAbove(uid))
|
|
84
|
+
) {
|
|
85
|
+
throw new HttpsError(
|
|
86
|
+
"permission-denied",
|
|
87
|
+
"Translator access required",
|
|
88
|
+
);
|
|
76
89
|
}
|
|
77
90
|
}
|
|
78
91
|
|