@dereekb/firebase 7.3.0 → 7.4.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/CHANGELOG.md +10 -0
- package/package.json +5 -5
- package/src/lib/common/auth/auth.context.d.ts +15 -3
- package/src/lib/common/firestore/snapshot/snapshot.field.d.ts +8 -5
- package/src/lib/common/firestore/snapshot/snapshot.field.js +3 -1
- package/src/lib/common/firestore/snapshot/snapshot.field.js.map +1 -1
- package/src/lib/common/model/context.d.ts +0 -6
- package/src/lib/common/model/permission/permission.service.d.ts +45 -2
- package/src/lib/common/model/permission/permission.service.js +55 -15
- package/src/lib/common/model/permission/permission.service.js.map +1 -1
- package/test/CHANGELOG.md +4 -0
- package/test/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [7.4.0](https://github.com/dereekb/dbx-components/compare/v7.3.0-dev...v7.4.0) (2022-06-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* added grantModelRolesIfFunction and related types ([5432fab](https://github.com/dereekb/dbx-components/commit/5432fab1677c29e24eac4015c35821aba2d64e10))
|
|
11
|
+
* updated FirebaseServerAuthUserContext to be synchronous ([92bfd84](https://github.com/dereekb/dbx-components/commit/92bfd849b4a6d6773c616069c3085b686938ef4d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
# [7.3.0](https://github.com/dereekb/dbx-components/compare/v7.2.0-dev...v7.3.0) (2022-06-08)
|
|
6
16
|
|
|
7
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@firebase/rules-unit-testing": "^2.0.0"
|
|
6
6
|
},
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"rxjs": "^7.0.0",
|
|
23
23
|
"rxfire": "^6.0.3",
|
|
24
24
|
"firebase": "^9.8.0",
|
|
25
|
-
"@dereekb/util": "7.
|
|
25
|
+
"@dereekb/util": "7.4.0",
|
|
26
26
|
"make-error": "^1.3.0",
|
|
27
27
|
"ts-essentials": "^9.1.2",
|
|
28
28
|
"extra-set": "^2.2.11",
|
|
29
|
-
"@dereekb/rxjs": "7.
|
|
29
|
+
"@dereekb/rxjs": "7.4.0",
|
|
30
30
|
"ms": "^3.0.0-canary.1",
|
|
31
|
-
"@dereekb/model": "7.
|
|
31
|
+
"@dereekb/model": "7.4.0",
|
|
32
32
|
"class-transformer": "^0.5.1",
|
|
33
33
|
"class-validator": "^0.13.2",
|
|
34
|
-
"@dereekb/date": "7.
|
|
34
|
+
"@dereekb/date": "7.4.0",
|
|
35
35
|
"date-fns": "^2.28.0",
|
|
36
36
|
"date-fns-tz": "^1.3.0",
|
|
37
37
|
"rrule": "git+https://git@github.com/dereekb/rrule.git#17adf5708d6567b4d01a3a8afd106261421ea492",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthClaims, AuthRoleSet, Maybe } from '@dereekb/util';
|
|
1
|
+
import { AuthClaims, AuthClaimsObject, AuthRoleSet, Maybe } from '@dereekb/util';
|
|
2
2
|
import { FirebaseAuthToken } from './auth';
|
|
3
3
|
/**
|
|
4
4
|
* Provides a context containing FirebaseAuthContextInfo
|
|
@@ -17,14 +17,26 @@ export interface FirebaseAuthContextInfo {
|
|
|
17
17
|
/**
|
|
18
18
|
* Returns true if the user is considered a system admin.
|
|
19
19
|
*/
|
|
20
|
-
isAdmin
|
|
20
|
+
isAdmin(): boolean;
|
|
21
21
|
/**
|
|
22
22
|
* Retrieves the claims in the context.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
getClaims<T extends AuthClaimsObject = AuthClaimsObject>(): AuthClaims<T>;
|
|
25
25
|
/**
|
|
26
26
|
* The auth roles provided by the token in this context.
|
|
27
27
|
*/
|
|
28
|
+
getAuthRoles(): AuthRoleSet;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the claims in the context.
|
|
31
|
+
*
|
|
32
|
+
* @deprecated Claims are now available synchronously.
|
|
33
|
+
*/
|
|
34
|
+
loadClaims<T extends AuthClaimsObject = AuthClaimsObject>(): Promise<AuthClaims<T>>;
|
|
35
|
+
/**
|
|
36
|
+
* The auth roles provided by the token in this context.
|
|
37
|
+
*
|
|
38
|
+
* @deprecated Auth role set is now available synchronously.
|
|
39
|
+
*/
|
|
28
40
|
loadAuthRoles(): Promise<AuthRoleSet>;
|
|
29
41
|
/**
|
|
30
42
|
* The token in the context.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GrantedRole } from '@dereekb/model';
|
|
2
|
+
import { ModelFieldMapFunctionsConfig, GetterOrValue, Maybe, ModelFieldMapConvertFunction, PrimativeKey, ReadKeyFunction, ModelFieldMapFunctionsWithDefaultsConfig, FindUniqueFunction, FindUniqueStringsTransformConfig, MapFunction, FilterKeyValueTuplesInput, ModelKey } from '@dereekb/util';
|
|
2
3
|
export interface BaseFirestoreFieldConfig<V, D = unknown> {
|
|
3
4
|
fromData: ModelFieldMapConvertFunction<D, V>;
|
|
4
5
|
toData: ModelFieldMapConvertFunction<V, D>;
|
|
@@ -33,6 +34,8 @@ export declare function firestoreString(config?: FirestoreStringConfig): Firesto
|
|
|
33
34
|
export declare function optionalFirestoreString(): ModelFieldMapFunctionsConfig<Maybe<string>, Maybe<string>>;
|
|
34
35
|
export declare function firestoreUID(): FirestoreModelFieldMapFunctionsConfig<string, string>;
|
|
35
36
|
export declare function optionalFirestoreUID(): ModelFieldMapFunctionsConfig<Maybe<string>, Maybe<string>>;
|
|
37
|
+
export declare const firestoreModelKey: FirestoreModelFieldMapFunctionsConfig<string, string>;
|
|
38
|
+
export declare const firestoreModelId: FirestoreModelFieldMapFunctionsConfig<string, string>;
|
|
36
39
|
export declare type FirestoreDateFieldConfig = DefaultMapConfiguredFirestoreFieldConfig<Date, string> & {
|
|
37
40
|
saveDefaultAsNow?: boolean;
|
|
38
41
|
};
|
|
@@ -112,13 +115,13 @@ export declare function firestoreMap<T, K extends string = string>(config?: Fire
|
|
|
112
115
|
*
|
|
113
116
|
* Filters out models with no/null roles by default.
|
|
114
117
|
*/
|
|
115
|
-
export declare function firestoreModelKeyGrantedRoleMap(): FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<
|
|
118
|
+
export declare function firestoreModelKeyGrantedRoleMap<R extends GrantedRole>(): FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<R, string>, FirestoreMapFieldType<R, string>>;
|
|
116
119
|
/**
|
|
117
120
|
* FirestoreField configuration for a map of granted roles, keyed by model ids.
|
|
118
121
|
*
|
|
119
122
|
* Filters out models with no/null roles by default.
|
|
120
123
|
*/
|
|
121
|
-
export declare const firestoreModelIdGrantedRoleMap:
|
|
124
|
+
export declare const firestoreModelIdGrantedRoleMap: () => FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<ModelKey, string>, FirestoreMapFieldType<ModelKey, string>>;
|
|
122
125
|
/**
|
|
123
126
|
* FirestoreField configuration for a map-type object with array values.
|
|
124
127
|
*
|
|
@@ -133,13 +136,13 @@ export declare function firestoreArrayMap<T, K extends string = string>(config?:
|
|
|
133
136
|
*
|
|
134
137
|
* Filters empty roles/arrays by default.
|
|
135
138
|
*/
|
|
136
|
-
export declare function firestoreModelKeyGrantedRoleArrayMap(): FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<
|
|
139
|
+
export declare function firestoreModelKeyGrantedRoleArrayMap<R extends GrantedRole>(): FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<R[], string>, FirestoreMapFieldType<R[], string>>;
|
|
137
140
|
/**
|
|
138
141
|
* FirestoreField configuration for a map of granted roles, keyed by models ids.
|
|
139
142
|
*
|
|
140
143
|
* Filters empty roles/arrays by default.
|
|
141
144
|
*/
|
|
142
|
-
export declare const firestoreModelIdGrantedRoleArrayMap:
|
|
145
|
+
export declare const firestoreModelIdGrantedRoleArrayMap: () => FirestoreModelFieldMapFunctionsConfig<FirestoreMapFieldType<ModelKey[], string>, FirestoreMapFieldType<ModelKey[], string>>;
|
|
143
146
|
export declare type FirestoreSetFieldConfig<T extends string | number> = DefaultMapConfiguredFirestoreFieldConfig<Set<T>, T[]>;
|
|
144
147
|
/**
|
|
145
148
|
* Do not use.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.firestoreSet = exports.firestoreModelIdGrantedRoleArrayMap = exports.firestoreModelKeyGrantedRoleArrayMap = exports.firestoreArrayMap = exports.firestoreModelIdGrantedRoleMap = exports.firestoreModelKeyGrantedRoleMap = exports.firestoreMap = exports.firestoreEncodedArray = exports.firestoreModelIdArray = exports.firestoreModelKeyArray = exports.firestoreUniqueStringArray = exports.firestoreUniqueKeyedArray = exports.firestoreUniqueArray = exports.optionalFirestoreArray = exports.firestoreArray = exports.optionalFirestoreNumber = exports.firestoreNumber = exports.optionalFirestoreBoolean = exports.firestoreBoolean = exports.optionalFirestoreDate = exports.firestoreDate = exports.optionalFirestoreUID = exports.firestoreUID = exports.optionalFirestoreString = exports.firestoreString = exports.firestorePassThroughField = exports.FIRESTORE_PASSTHROUGH_FIELD = exports.firestoreField = void 0;
|
|
3
|
+
exports.firestoreSet = exports.firestoreModelIdGrantedRoleArrayMap = exports.firestoreModelKeyGrantedRoleArrayMap = exports.firestoreArrayMap = exports.firestoreModelIdGrantedRoleMap = exports.firestoreModelKeyGrantedRoleMap = exports.firestoreMap = exports.firestoreEncodedArray = exports.firestoreModelIdArray = exports.firestoreModelKeyArray = exports.firestoreUniqueStringArray = exports.firestoreUniqueKeyedArray = exports.firestoreUniqueArray = exports.optionalFirestoreArray = exports.firestoreArray = exports.optionalFirestoreNumber = exports.firestoreNumber = exports.optionalFirestoreBoolean = exports.firestoreBoolean = exports.optionalFirestoreDate = exports.firestoreDate = exports.firestoreModelId = exports.firestoreModelKey = exports.optionalFirestoreUID = exports.firestoreUID = exports.optionalFirestoreString = exports.firestoreString = exports.firestorePassThroughField = exports.FIRESTORE_PASSTHROUGH_FIELD = exports.firestoreField = void 0;
|
|
4
4
|
const date_1 = require("@dereekb/date");
|
|
5
5
|
const util_1 = require("@dereekb/util");
|
|
6
6
|
const snapshot_1 = require("./snapshot");
|
|
@@ -50,6 +50,8 @@ function optionalFirestoreUID() {
|
|
|
50
50
|
return optionalFirestoreString();
|
|
51
51
|
}
|
|
52
52
|
exports.optionalFirestoreUID = optionalFirestoreUID;
|
|
53
|
+
exports.firestoreModelKey = firestoreString();
|
|
54
|
+
exports.firestoreModelId = firestoreString();
|
|
53
55
|
function firestoreDate(config = {}) {
|
|
54
56
|
var _a, _b;
|
|
55
57
|
return firestoreField({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.field.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/snapshot.field.ts"],"names":[],"mappings":";;;AAEA,wCAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"snapshot.field.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/firestore/snapshot/snapshot.field.ts"],"names":[],"mappings":";;;AAEA,wCAA4E;AAC5E,wCAAmf;AACnf,yCAAmD;AA4BnD,SAAgB,cAAc,CAAiB,MAAkC;;IAC/E,OAAO;QACL,IAAI,EAAG,MAAgD,CAAC,OAAO;YAC7D,CAAC,CAAC;gBACE,OAAO,EAAG,MAAgD,CAAC,OAAO;gBAClE,OAAO,EAAE,MAAM,CAAC,QAAQ;aACzB;YACH,CAAC,CAAC;gBACE,YAAY,EAAG,MAAoD,CAAC,WAAW;gBAC/E,OAAO,EAAE,MAAM,C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L,CAAC;AAJD,oFAIC;AAED;;;;GAIG;AACU,QAAA,mCAAmC,GAAsI,oCAAoC,CAAC;AAK3N;;;;;;;GAOG;AACH,SAAgB,YAAY,CAA4B,MAAkC;;IACxF,OAAO,cAAc,CAAc;QACjC,OAAO,EAAE,MAAA,MAAM,CAAC,OAAO,mCAAI,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC;QAC5C,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC;QACjC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;KACjC,CAAC,CAAC;AACL,CAAC;AAND,oCAMC"}
|
|
@@ -4,12 +4,6 @@ import { FirebasePermissionContext, FirebasePermissionErrorContext } from './per
|
|
|
4
4
|
* A base model context that contains info about what is current occuring.
|
|
5
5
|
*/
|
|
6
6
|
export interface FirebaseModelContext extends FirebasePermissionContext, FirebasePermissionErrorContext, FirebaseAuthContext {
|
|
7
|
-
/**
|
|
8
|
-
* Whether or not to return all role checks for models as true if the auth context shows the current user as an admin.
|
|
9
|
-
*
|
|
10
|
-
* Is false by default.
|
|
11
|
-
*/
|
|
12
|
-
readonly adminGetsAllowAllRoles?: boolean;
|
|
13
7
|
}
|
|
14
8
|
export interface FirebaseAppModelContext<C> extends FirebaseModelContext {
|
|
15
9
|
readonly app: C;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FirestoreDocument } from './../../firestore';
|
|
2
2
|
import { AbstractModelPermissionService, GrantedRoleMap, InContextModelPermissionService, InModelContextModelPermissionService, ModelPermissionService } from '@dereekb/model';
|
|
3
|
-
import { Maybe, PromiseOrValue } from '@dereekb/util';
|
|
3
|
+
import { DecisionFunction, Getter, GetterOrValue, Maybe, PromiseOrValue } from '@dereekb/util';
|
|
4
4
|
import { FirebaseModelLoader, InModelContextFirebaseModelLoader } from '../model/model.loader';
|
|
5
5
|
import { FirebaseModelContext } from '../context';
|
|
6
6
|
import { FirebasePermissionServiceModel } from './permission';
|
|
@@ -16,9 +16,52 @@ export declare class FirebaseModelPermissionServiceInstance<C extends FirebaseMo
|
|
|
16
16
|
constructor(delegate: FirebasePermissionServiceInstanceDelegate<C, T, D, R>);
|
|
17
17
|
roleMapForModel(output: FirebasePermissionServiceModel<T, D>, context: C, model: D): PromiseOrValue<GrantedRoleMap<R>>;
|
|
18
18
|
protected outputForModel(document: D): Promise<Maybe<FirebasePermissionServiceModel<T, D>>>;
|
|
19
|
-
protected getRoleMapForOutput(output: FirebasePermissionServiceModel<T, D>, context: C, model: D): Promise<import("@dereekb/model").ContextGrantedModelRoles<FirebasePermissionServiceModel<T, D>, C, R>>;
|
|
20
19
|
protected isUsableOutputForRoles(output: FirebasePermissionServiceModel<T, D>): boolean;
|
|
21
20
|
}
|
|
22
21
|
export declare function firebaseModelPermissionService<C extends FirebaseModelContext, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string>(delegate: FirebasePermissionServiceInstanceDelegate<C, T, D, R>): FirebaseModelPermissionServiceInstance<C, T, D, R>;
|
|
23
22
|
export declare type InContextFirebaseModelPermissionService<C, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string> = InContextModelPermissionService<C, D, R, FirebasePermissionServiceModel<T, D>>;
|
|
24
23
|
export declare type InModelContextFirebaseModelPermissionService<C, T, D extends FirestoreDocument<T> = FirestoreDocument<T>, R extends string = string> = InModelContextModelPermissionService<C, D, R, FirebasePermissionServiceModel<T, D>> & InModelContextFirebaseModelLoader<T, D>;
|
|
24
|
+
export declare const grantFullAccessIfAdmin: GeneralGrantRolesIfFunction;
|
|
25
|
+
export declare function grantModelRolesIfAdmin<R extends string = string>(context: FirebaseModelContext, rolesToGrantToAdmin: GetterOrValue<GrantedRoleMap<R>>, otherwise?: () => GrantedRoleMap<R>): GrantedRoleMap<R>;
|
|
26
|
+
/**
|
|
27
|
+
* Convenience function that checks the input context if the user is an admin or not and grants pre-set admin roles if they are.
|
|
28
|
+
*
|
|
29
|
+
* @param context
|
|
30
|
+
* @param rolesToGrantToAdmin
|
|
31
|
+
* @param otherwise
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function grantModelRolesIfAdminFunction<R extends string = string>(rolesToGrantToAdmin: GetterOrValue<GrantedRoleMap<R>>): GrantRolesIfFunction<R>;
|
|
35
|
+
/**
|
|
36
|
+
* DecisionFunction for a FirebaseModelContext that checks if the current user is an admin.
|
|
37
|
+
*
|
|
38
|
+
* @param context
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export declare const isAdminInFirebaseModelContext: DecisionFunction<FirebaseModelContext>;
|
|
42
|
+
/**
|
|
43
|
+
* Grants the configured roles if the decision is made about the context. Otherwise, returns a NoAccessRoleMap.
|
|
44
|
+
*/
|
|
45
|
+
export declare type GrantRolesOnlyIfFunction<R extends string = string, C extends FirebaseModelContext = FirebaseModelContext> = (context: C) => GrantedRoleMap<R>;
|
|
46
|
+
export declare type GeneralGrantRolesOnlyIfFunction = <R extends string = string, C extends FirebaseModelContext = FirebaseModelContext>(context: C) => GrantedRoleMap<R>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a GrantRolesOnlyIfFunction
|
|
49
|
+
*
|
|
50
|
+
* @param grantIf
|
|
51
|
+
* @param grantedRoles
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
export declare function grantModelRolesOnlyIfFunction<C extends FirebaseModelContext, R extends string = string>(grantIf: DecisionFunction<C>, grantedRoles: GetterOrValue<GrantedRoleMap<R>>): GrantRolesOnlyIfFunction<R, C>;
|
|
55
|
+
/**
|
|
56
|
+
* Grants the configured roles if the decision is made about the context. Otherwise, invokes the otherwise function if available, or returns a NoAccessRoleMap.
|
|
57
|
+
*/
|
|
58
|
+
export declare type GrantRolesIfFunction<R extends string = string, C extends FirebaseModelContext = FirebaseModelContext> = (context: C, otherwise?: Getter<GrantedRoleMap<R>>) => GrantedRoleMap<R>;
|
|
59
|
+
export declare type GeneralGrantRolesIfFunction = <R extends string = string, C extends FirebaseModelContext = FirebaseModelContext>(context: C, otherwise?: Getter<GrantedRoleMap<R>>) => GrantedRoleMap<R>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a GrantRolesIfFunction.
|
|
62
|
+
*
|
|
63
|
+
* @param grantIf
|
|
64
|
+
* @param grantedRoles
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
export declare function grantModelRolesIfFunction<C extends FirebaseModelContext, R extends string = string>(grantIf: DecisionFunction<C>, grantedRoles: GetterOrValue<GrantedRoleMap<R>>): GrantRolesIfFunction<R, C>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.firebaseModelPermissionService = exports.FirebaseModelPermissionServiceInstance = void 0;
|
|
3
|
+
exports.grantModelRolesIfFunction = exports.grantModelRolesOnlyIfFunction = exports.isAdminInFirebaseModelContext = exports.grantModelRolesIfAdminFunction = exports.grantModelRolesIfAdmin = exports.grantFullAccessIfAdmin = exports.firebaseModelPermissionService = exports.FirebaseModelPermissionServiceInstance = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const model_1 = require("@dereekb/model");
|
|
6
|
+
const util_1 = require("@dereekb/util");
|
|
6
7
|
/**
|
|
7
8
|
* Abstract AbstractModelPermissionService implementation for FirebaseModelsPermissionService.
|
|
8
9
|
*/
|
|
@@ -22,20 +23,6 @@ class FirebaseModelPermissionServiceInstance extends model_1.AbstractModelPermis
|
|
|
22
23
|
return model;
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
|
-
getRoleMapForOutput(output, context, model) {
|
|
26
|
-
const _super = Object.create(null, {
|
|
27
|
-
getRoleMapForOutput: { get: () => super.getRoleMapForOutput }
|
|
28
|
-
});
|
|
29
|
-
var _a, _b;
|
|
30
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
if (context.adminGetsAllowAllRoles && ((_b = (_a = context.auth) === null || _a === void 0 ? void 0 : _a.isAdmin) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
|
32
|
-
return (0, model_1.fullAccessGrantedModelRoles)(context, output);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return _super.getRoleMapForOutput.call(this, output, context, model);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
26
|
isUsableOutputForRoles(output) {
|
|
40
27
|
return output.exists;
|
|
41
28
|
}
|
|
@@ -45,4 +32,57 @@ function firebaseModelPermissionService(delegate) {
|
|
|
45
32
|
return new FirebaseModelPermissionServiceInstance(delegate);
|
|
46
33
|
}
|
|
47
34
|
exports.firebaseModelPermissionService = firebaseModelPermissionService;
|
|
35
|
+
// MARK: Utility
|
|
36
|
+
exports.grantFullAccessIfAdmin = grantModelRolesIfAdminFunction(model_1.fullAccessRoleMap);
|
|
37
|
+
function grantModelRolesIfAdmin(context, rolesToGrantToAdmin, otherwise) {
|
|
38
|
+
return grantModelRolesIfAdminFunction(rolesToGrantToAdmin)(context, otherwise);
|
|
39
|
+
}
|
|
40
|
+
exports.grantModelRolesIfAdmin = grantModelRolesIfAdmin;
|
|
41
|
+
/**
|
|
42
|
+
* Convenience function that checks the input context if the user is an admin or not and grants pre-set admin roles if they are.
|
|
43
|
+
*
|
|
44
|
+
* @param context
|
|
45
|
+
* @param rolesToGrantToAdmin
|
|
46
|
+
* @param otherwise
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
function grantModelRolesIfAdminFunction(rolesToGrantToAdmin) {
|
|
50
|
+
return grantModelRolesIfFunction(exports.isAdminInFirebaseModelContext, rolesToGrantToAdmin);
|
|
51
|
+
}
|
|
52
|
+
exports.grantModelRolesIfAdminFunction = grantModelRolesIfAdminFunction;
|
|
53
|
+
/**
|
|
54
|
+
* DecisionFunction for a FirebaseModelContext that checks if the current user is an admin.
|
|
55
|
+
*
|
|
56
|
+
* @param context
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
const isAdminInFirebaseModelContext = (context) => { var _a, _b; return (_b = (_a = context.auth) === null || _a === void 0 ? void 0 : _a.isAdmin()) !== null && _b !== void 0 ? _b : false; };
|
|
60
|
+
exports.isAdminInFirebaseModelContext = isAdminInFirebaseModelContext;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a GrantRolesOnlyIfFunction
|
|
63
|
+
*
|
|
64
|
+
* @param grantIf
|
|
65
|
+
* @param grantedRoles
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
function grantModelRolesOnlyIfFunction(grantIf, grantedRoles) {
|
|
69
|
+
const fn = grantModelRolesIfFunction(grantIf, grantedRoles);
|
|
70
|
+
return (context) => fn(context);
|
|
71
|
+
}
|
|
72
|
+
exports.grantModelRolesOnlyIfFunction = grantModelRolesOnlyIfFunction;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a GrantRolesIfFunction.
|
|
75
|
+
*
|
|
76
|
+
* @param grantIf
|
|
77
|
+
* @param grantedRoles
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
function grantModelRolesIfFunction(grantIf, grantedRoles) {
|
|
81
|
+
return (context, otherwise = model_1.noAccessRoleMap) => {
|
|
82
|
+
const decision = grantIf(context);
|
|
83
|
+
const results = decision ? (0, util_1.getValueFromGetter)(grantedRoles) : otherwise();
|
|
84
|
+
return results;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.grantModelRolesIfFunction = grantModelRolesIfFunction;
|
|
48
88
|
//# sourceMappingURL=permission.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.service.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib/common/model/permission/permission.service.ts"],"names":[],"mappings":";;;;AACA,
|
|
1
|
+
{"version":3,"file":"permission.service.js","sourceRoot":"","sources":["../../../../../../../../packages/firebase/src/lib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,mBAAmB,CAAC,CAAC;AACvF,CAAC;AAFD,wEAEC;AAED;;;;;GAKG;AACI,MAAM,6BAA6B,GAA2C,CAAC,OAA6B,EAAE,EAAE,eAAC,OAAA,MAAA,MAAA,OAAO,CAAC,IAAI,0CAAE,OAAO,EAAE,mCAAI,KAAK,CAAA,EAAA,CAAC;AAA5I,QAAA,6BAA6B,iCAA+G;AAQzJ;;;;;;GAMG;AACH,SAAgB,6BAA6B,CAA4D,OAA4B,EAAE,YAA8C;IACnL,MAAM,EAAE,GAAG,yBAAyB,CAAO,OAAO,EAAE,YAAY,CAAC,CAAC;IAClE,OAAO,CAAC,OAAU,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAHD,sEAGC;AAQD;;;;;;GAMG;AACH,SAAgB,yBAAyB,CAA4D,OAA4B,EAAE,YAA8C;IAC/K,OAAO,CAAC,OAAU,EAAE,YAAuC,uBAAe,EAAE,EAAE;QAC5E,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAA,yBAAkB,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QAC1E,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC;AAND,8DAMC"}
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [7.4.0](https://github.com/dereekb/dbx-components/compare/v7.3.0-dev...v7.4.0) (2022-06-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
# [7.3.0](https://github.com/dereekb/dbx-components/compare/v7.2.0-dev...v7.3.0) (2022-06-08)
|
|
6
10
|
|
|
7
11
|
|
package/test/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dereekb/firebase/test",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"typings": "./src/index.d.ts",
|
|
6
6
|
"dependencies": {},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@dereekb/util/test": "7.
|
|
9
|
-
"@dereekb/util": "7.
|
|
8
|
+
"@dereekb/util/test": "7.4.0",
|
|
9
|
+
"@dereekb/util": "7.4.0",
|
|
10
10
|
"make-error": "^1.3.0",
|
|
11
11
|
"ts-essentials": "^9.1.2",
|
|
12
12
|
"extra-set": "^2.2.11",
|
|
13
|
-
"@dereekb/firebase": "7.
|
|
13
|
+
"@dereekb/firebase": "7.4.0",
|
|
14
14
|
"rxjs": "^7.0.0",
|
|
15
15
|
"rxfire": "^6.0.3",
|
|
16
16
|
"firebase": "^9.8.0",
|
|
17
|
-
"@dereekb/rxjs": "7.
|
|
17
|
+
"@dereekb/rxjs": "7.4.0",
|
|
18
18
|
"ms": "^3.0.0-canary.1",
|
|
19
|
-
"@dereekb/model": "7.
|
|
19
|
+
"@dereekb/model": "7.4.0",
|
|
20
20
|
"class-transformer": "^0.5.1",
|
|
21
21
|
"class-validator": "^0.13.2",
|
|
22
|
-
"@dereekb/date": "7.
|
|
22
|
+
"@dereekb/date": "7.4.0",
|
|
23
23
|
"date-fns": "^2.28.0",
|
|
24
24
|
"date-fns-tz": "^1.3.0",
|
|
25
25
|
"rrule": "git+https://git@github.com/dereekb/rrule.git#17adf5708d6567b4d01a3a8afd106261421ea492",
|