@genesislcap/foundation-filters 9.0.1-alpha-b5c5eb7.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/MODULE_FEDERATION.md +11 -0
- package/README.md +173 -0
- package/dist/1.0.0.remoteEntry.js +1 -0
- package/dist/191.191.64feeeeeb6c4132a6cae.js +2 -0
- package/dist/191.d7c8a7fc5c69e4190ea53a04618e0459.js.map +1 -0
- package/dist/195.195.2c71a4e018ba860ab228.js +3 -0
- package/dist/195.195.2c71a4e018ba860ab228.js.LICENSE.txt +4 -0
- package/dist/195.331a5c4d39a8a3d001d3344cb66ef3b8.js.map +1 -0
- package/dist/259.0acac2573f700ecd1acac239926438a5.js.map +1 -0
- package/dist/259.259.3aa926921ed1388957f1.js +2 -0
- package/dist/338.338.cd6e49db31e7adc808c6.js +3 -0
- package/dist/338.338.cd6e49db31e7adc808c6.js.LICENSE.txt +1 -0
- package/dist/338.7a143cd09921b756e7fe871d338dcb67.js.map +1 -0
- package/dist/410.410.76d9d4b118ba230b93c4.js +2 -0
- package/dist/410.cda4ae21eb38efbf2dbfd913db12d66f.js.map +1 -0
- package/dist/755.755.ec31a791472b4b3fcb0f.js +2 -0
- package/dist/755.c71c3a1801dd2c0461f8b831d09ec90f.js.map +1 -0
- package/dist/dashboard.json +1 -0
- package/dist/dts/clientFilter.d.ts +108 -0
- package/dist/dts/clientFilter.d.ts.map +1 -0
- package/dist/dts/index.d.ts +9 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/dts/index.federated.d.ts +1 -0
- package/dist/dts/index.federated.d.ts.map +1 -0
- package/dist/dts/logger.d.ts +17 -0
- package/dist/dts/logger.d.ts.map +1 -0
- package/dist/dts/nodeEnv.d.ts +81 -0
- package/dist/dts/nodeEnv.d.ts.map +1 -0
- package/dist/dts/percentage.d.ts +81 -0
- package/dist/dts/percentage.d.ts.map +1 -0
- package/dist/dts/timeWindow.d.ts +91 -0
- package/dist/dts/timeWindow.d.ts.map +1 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/urlTargeting.d.ts +94 -0
- package/dist/dts/urlTargeting.d.ts.map +1 -0
- package/dist/dts/userAgent.d.ts +96 -0
- package/dist/dts/userAgent.d.ts.map +1 -0
- package/dist/dts/userTargeting.d.ts +107 -0
- package/dist/dts/userTargeting.d.ts.map +1 -0
- package/dist/esm/clientFilter.js +84 -0
- package/dist/esm/clientFilter.js.map +1 -0
- package/dist/esm/index.federated.js +2 -0
- package/dist/esm/index.federated.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger.js +18 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/nodeEnv.js +48 -0
- package/dist/esm/nodeEnv.js.map +1 -0
- package/dist/esm/percentage.js +38 -0
- package/dist/esm/percentage.js.map +1 -0
- package/dist/esm/timeWindow.js +49 -0
- package/dist/esm/timeWindow.js.map +1 -0
- package/dist/esm/urlTargeting.js +68 -0
- package/dist/esm/urlTargeting.js.map +1 -0
- package/dist/esm/userAgent.js +59 -0
- package/dist/esm/userAgent.js.map +1 -0
- package/dist/esm/userTargeting.js +73 -0
- package/dist/esm/userTargeting.js.map +1 -0
- package/dist/favicon.ico +0 -0
- package/dist/foundation-filters.api.json +3065 -0
- package/dist/foundation-filters.d.ts +707 -0
- package/dist/foundation-filters.iife.min.js +3 -0
- package/dist/foundation-filters.js +8608 -0
- package/dist/foundation-filters.min.js +3 -0
- package/dist/foundationFilters.c0ca375607bf5b49304e9efbcfb9ec0d.js.map +1 -0
- package/dist/index.ejs +23 -0
- package/dist/index.html +16 -0
- package/dist/info.ejs +13 -0
- package/dist/main.479db3c6a61354c4d21c4a52177a4fc9.js.map +1 -0
- package/dist/main.8bf3ac27c0d922605d1f.js +2 -0
- package/dist/npm.analytics.343.d4561facd9660fd45482.js +2 -0
- package/dist/npm.analytics.50acd47759b15e99bc3ad79caad7c672.js.map +1 -0
- package/dist/npm.consola.0f92c98545c00deac8a01e6e5c25e63c.js.map +1 -0
- package/dist/npm.consola.713.4cfd0e26a2fd1e472409.js +2 -0
- package/dist/npm.finos.690.4b909dcccf246b8fb074.js +2 -0
- package/dist/npm.finos.83f8bd7cc8c58aabd1049256a8d005fe.js.map +1 -0
- package/dist/npm.microsoft.127.2934a743e3e0797a43e6.js +1469 -0
- package/dist/npm.microsoft.127.2934a743e3e0797a43e6.js.LICENSE.txt +14 -0
- package/dist/npm.microsoft.e17056c760df168ceb07617558d61f7e.js.map +1 -0
- package/dist/npm.rxjs.271.11caf676e6c2aaf1715a.js +2 -0
- package/dist/npm.rxjs.2d42120c7dd915e4ea92bdec64a19f45.js.map +1 -0
- package/dist/npm.ua-parser-js.809.92491f7cd444ab77d377.js +2 -0
- package/dist/npm.ua-parser-js.b1390f6f6c6080318a30bc73abe8add8.js.map +1 -0
- package/dist/remoteEntry.js +2 -0
- package/dist/serve.json +3 -0
- package/docs/api/foundation-filters.clientfilter.filter.md +24 -0
- package/docs/api/foundation-filters.clientfilter.md +24 -0
- package/docs/api/foundation-filters.clientfiltername.md +19 -0
- package/docs/api/foundation-filters.clientfilterrunner.md +20 -0
- package/docs/api/foundation-filters.clientfilterrunner.run.md +23 -0
- package/docs/api/foundation-filters.clientfilterschema.md +22 -0
- package/docs/api/foundation-filters.clientfilterschemas.md +15 -0
- package/docs/api/foundation-filters.defaultclientfilterrunner.container.md +11 -0
- package/docs/api/foundation-filters.defaultclientfilterrunner.md +27 -0
- package/docs/api/foundation-filters.defaultclientfilterrunner.run.md +23 -0
- package/docs/api/foundation-filters.defaultnodeenv.filter.md +24 -0
- package/docs/api/foundation-filters.defaultnodeenv.isdevelopment.md +16 -0
- package/docs/api/foundation-filters.defaultnodeenv.isproduction.md +16 -0
- package/docs/api/foundation-filters.defaultnodeenv.istesting.md +16 -0
- package/docs/api/foundation-filters.defaultnodeenv.md +29 -0
- package/docs/api/foundation-filters.defaultpercentage.filter.md +24 -0
- package/docs/api/foundation-filters.defaultpercentage.md +21 -0
- package/docs/api/foundation-filters.defaulttimewindow.filter.md +24 -0
- package/docs/api/foundation-filters.defaulttimewindow.md +21 -0
- package/docs/api/foundation-filters.defaulturltargeting.filter.md +24 -0
- package/docs/api/foundation-filters.defaulturltargeting.issecure.md +26 -0
- package/docs/api/foundation-filters.defaulturltargeting.md +22 -0
- package/docs/api/foundation-filters.defaultuseragent.filter.md +24 -0
- package/docs/api/foundation-filters.defaultuseragent.issafari.md +16 -0
- package/docs/api/foundation-filters.defaultuseragent.md +27 -0
- package/docs/api/foundation-filters.defaultusertargeting._constructor_.md +20 -0
- package/docs/api/foundation-filters.defaultusertargeting.auth.md +11 -0
- package/docs/api/foundation-filters.defaultusertargeting.filter.md +24 -0
- package/docs/api/foundation-filters.defaultusertargeting.hasadminprofile.md +16 -0
- package/docs/api/foundation-filters.defaultusertargeting.isloggedin.md +16 -0
- package/docs/api/foundation-filters.defaultusertargeting.md +35 -0
- package/docs/api/foundation-filters.getfilterbyname.md +25 -0
- package/docs/api/foundation-filters.logger.md +27 -0
- package/docs/api/foundation-filters.md +71 -0
- package/docs/api/foundation-filters.nodeenv.isdevelopment.md +16 -0
- package/docs/api/foundation-filters.nodeenv.isproduction.md +16 -0
- package/docs/api/foundation-filters.nodeenv.istesting.md +16 -0
- package/docs/api/foundation-filters.nodeenv.md +23 -0
- package/docs/api/foundation-filters.nodeenvfilter.md +28 -0
- package/docs/api/foundation-filters.nodeenvparams.md +25 -0
- package/docs/api/foundation-filters.nodeenvschema.md +19 -0
- package/docs/api/foundation-filters.percentage.md +19 -0
- package/docs/api/foundation-filters.percentagefilter.md +29 -0
- package/docs/api/foundation-filters.percentageparams.md +41 -0
- package/docs/api/foundation-filters.percentageschema.md +19 -0
- package/docs/api/foundation-filters.runner.md +29 -0
- package/docs/api/foundation-filters.timewindow.md +19 -0
- package/docs/api/foundation-filters.timewindowfilter.md +29 -0
- package/docs/api/foundation-filters.timewindowparams.md +59 -0
- package/docs/api/foundation-filters.timewindowschema.md +19 -0
- package/docs/api/foundation-filters.urltargeting.issecure.md +26 -0
- package/docs/api/foundation-filters.urltargeting.md +21 -0
- package/docs/api/foundation-filters.urltargetingfilter.md +32 -0
- package/docs/api/foundation-filters.urltargetingparams.md +30 -0
- package/docs/api/foundation-filters.urltargetingschema.md +19 -0
- package/docs/api/foundation-filters.useragent.issafari.md +16 -0
- package/docs/api/foundation-filters.useragent.md +25 -0
- package/docs/api/foundation-filters.useragentfilter.md +31 -0
- package/docs/api/foundation-filters.useragentparams.md +30 -0
- package/docs/api/foundation-filters.useragentschema.md +19 -0
- package/docs/api/foundation-filters.usertargeting.hasadminprofile.md +16 -0
- package/docs/api/foundation-filters.usertargeting.isloggedin.md +16 -0
- package/docs/api/foundation-filters.usertargeting.md +26 -0
- package/docs/api/foundation-filters.usertargetingfilter.md +31 -0
- package/docs/api/foundation-filters.usertargetingparams.md +29 -0
- package/docs/api/foundation-filters.usertargetingschema.md +19 -0
- package/docs/api/index.md +12 -0
- package/docs/api-report.md +283 -0
- package/jsdom.setup.ts +1 -0
- package/license.txt +46 -0
- package/package.json +122 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Auth, User } from '@genesislcap/foundation-comms';
|
|
2
|
+
import type { ClientFilter, ClientFilterName, ClientFilterSchema } from './clientFilter';
|
|
3
|
+
/**
|
|
4
|
+
* UserTargeting client filter function.
|
|
5
|
+
* @remarks
|
|
6
|
+
* This will return true when the current user matches on ANY of the parameters. If you wish to match on multiple
|
|
7
|
+
* parameters, consider chaining an array of userTargeting filters together.
|
|
8
|
+
* @param user - A user object.
|
|
9
|
+
* @param usernames - Usernames to target.
|
|
10
|
+
* @param profiles - Profiles to target.
|
|
11
|
+
* @param permissions - Permissions to target.
|
|
12
|
+
* @public
|
|
13
|
+
* @privateRemarks
|
|
14
|
+
* We could provide another parameter to indicate a complete match is required?
|
|
15
|
+
*/
|
|
16
|
+
export declare function userTargetingFilter(user: User, usernames?: string[], profiles?: string[], permissions?: string[]): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* UserTargetingParams
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```json
|
|
22
|
+
* {
|
|
23
|
+
* "usernames": ["JohnDoe"],
|
|
24
|
+
* "profiles": ["ADMIN", "READ_WRITE_DEALER"],
|
|
25
|
+
* "permissions": ["ExportClientDashboard"]
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export type UserTargetingParams = {
|
|
32
|
+
/**
|
|
33
|
+
* Usernames to target.
|
|
34
|
+
*/
|
|
35
|
+
readonly usernames?: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Profiles to target.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Profiles are assigned to users, and users may have multiple profiles assigned to them.
|
|
41
|
+
*/
|
|
42
|
+
readonly profiles?: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Permissions to target.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Permissions are assigned to profiles, NEVER to users directly.
|
|
48
|
+
* The user permissions array will contain everything from the assigned profiles for fine-grained control.
|
|
49
|
+
*/
|
|
50
|
+
readonly permissions?: string[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* UserTargetingSchema type.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* JSON schema type.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export type UserTargetingSchema = ClientFilterSchema<typeof ClientFilterName.userTargeting, UserTargetingParams>;
|
|
61
|
+
/**
|
|
62
|
+
* UserTargeting client filter DI interface.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* Simplifies access to runtime data / state contained within the DI container.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export interface UserTargeting extends ClientFilter<UserTargetingParams> {
|
|
70
|
+
/**
|
|
71
|
+
* @remarks
|
|
72
|
+
* Has the user got the 'ADMIN' profile assigned.
|
|
73
|
+
*
|
|
74
|
+
* @privateRemarks
|
|
75
|
+
* Added as an example, see comment in implementation.
|
|
76
|
+
*/
|
|
77
|
+
readonly hasAdminProfile: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* @remarks
|
|
80
|
+
* Has the user logged in, regardless of their identity.
|
|
81
|
+
*/
|
|
82
|
+
readonly isLoggedIn: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Default UserTargeting DI implementation.
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export declare class DefaultUserTargeting implements UserTargeting {
|
|
89
|
+
auth: Auth;
|
|
90
|
+
constructor(auth: Auth);
|
|
91
|
+
/** {@inheritDoc ClientFilter.filter} */
|
|
92
|
+
filter(params: UserTargetingParams): boolean;
|
|
93
|
+
/** {@inheritDoc UserTargeting.hasAdminProfile} */
|
|
94
|
+
get hasAdminProfile(): boolean;
|
|
95
|
+
/** {@inheritDoc UserTargeting.isLoggedIn} */
|
|
96
|
+
get isLoggedIn(): boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* UserTargeting DI key.
|
|
100
|
+
*
|
|
101
|
+
* @privateRemarks
|
|
102
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
103
|
+
*
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
export declare const UserTargeting: import("@microsoft/fast-foundation").InterfaceSymbol<UserTargeting>;
|
|
107
|
+
//# sourceMappingURL=userTargeting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userTargeting.d.ts","sourceRoot":"","sources":["../../src/userTargeting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,k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
import { logger } from './logger';
|
|
4
|
+
import { NodeEnv } from './nodeEnv';
|
|
5
|
+
import { Percentage } from './percentage';
|
|
6
|
+
import { TimeWindow } from './timeWindow';
|
|
7
|
+
import { URLTargeting } from './urlTargeting';
|
|
8
|
+
import { UserAgent } from './userAgent';
|
|
9
|
+
import { UserTargeting } from './userTargeting';
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export const ClientFilterName = {
|
|
14
|
+
nodeEnv: 'nodeEnv',
|
|
15
|
+
percentage: 'percentage',
|
|
16
|
+
timeWindow: 'timeWindow',
|
|
17
|
+
urlTargeting: 'urlTargeting',
|
|
18
|
+
userAgent: 'userAgent',
|
|
19
|
+
userTargeting: 'userTargeting',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Filer lookup by name.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export function getFilterByName(name, container) {
|
|
27
|
+
switch (name) {
|
|
28
|
+
case ClientFilterName.nodeEnv:
|
|
29
|
+
return container.get(NodeEnv);
|
|
30
|
+
case ClientFilterName.percentage:
|
|
31
|
+
return container.get(Percentage);
|
|
32
|
+
case ClientFilterName.timeWindow:
|
|
33
|
+
return container.get(TimeWindow);
|
|
34
|
+
case ClientFilterName.urlTargeting:
|
|
35
|
+
return container.get(URLTargeting);
|
|
36
|
+
case ClientFilterName.userAgent:
|
|
37
|
+
return container.get(UserAgent);
|
|
38
|
+
case ClientFilterName.userTargeting:
|
|
39
|
+
return container.get(UserTargeting);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Client filter runner function.
|
|
44
|
+
* @remarks
|
|
45
|
+
* This will return true when all the filters in the array pass.
|
|
46
|
+
* @param filters - An array of client filters to run.
|
|
47
|
+
* @param container - The DI container.
|
|
48
|
+
* @public
|
|
49
|
+
* @privateRemarks
|
|
50
|
+
* As a runner working off static input, we can't know or source the runtime dependencies of each filter. As such we use
|
|
51
|
+
* the DI version of each which have those encapsulated.
|
|
52
|
+
*/
|
|
53
|
+
export function runner(filters, container) {
|
|
54
|
+
if (!filters || !filters.length) {
|
|
55
|
+
logger.warn('The client filter runner requires an array of filters to run, received:', filters);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return filters.every((cf) => {
|
|
59
|
+
const target = getFilterByName(cf.name, container);
|
|
60
|
+
return target ? target.filter(cf.parameters) : true;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Default ClientFilterRunner DI implementation.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export class DefaultClientFilterRunner {
|
|
68
|
+
run(filters, container = this.container) {
|
|
69
|
+
return runner(filters, container);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
__decorate([
|
|
73
|
+
Container
|
|
74
|
+
], DefaultClientFilterRunner.prototype, "container", void 0);
|
|
75
|
+
/**
|
|
76
|
+
* ClientFilterRunner DI key.
|
|
77
|
+
*
|
|
78
|
+
* @privateRemarks
|
|
79
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export const ClientFilterRunner = DI.createInterface((x) => x.transient(DefaultClientFilterRunner));
|
|
84
|
+
//# sourceMappingURL=clientFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientFilter.js","sourceRoot":"","sources":["../../src/clientFilter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAiB,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAoB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAoB,MAAM,cAAc,CAAC;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,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE;QAC1B,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAiB,CAAC;QACnE,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC;AAWD;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IAEpC,GAAG,CAAC,OAA8B,EAAE,SAAS,GAAG,IAAI,CAAC,SAAS;QAC5D,OAAO,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;CACF;AAJY;IAAV,SAAS;4DAAuB;AAMnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC,eAAe,CAAqB,CAAC,CAAC,EAAE,EAAE,CAC7E,CAAC,CAAC,SAAS,CAAC,yBAAyB,CAAC,CACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.federated.js","sourceRoot":"","sources":["../../src/index.federated.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './clientFilter';
|
|
2
|
+
export * from './logger';
|
|
3
|
+
export * from './nodeEnv';
|
|
4
|
+
export * from './percentage';
|
|
5
|
+
export * from './timeWindow';
|
|
6
|
+
export * from './urlTargeting';
|
|
7
|
+
export * from './userAgent';
|
|
8
|
+
export * from './userTargeting';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createLogger } from '@genesislcap/foundation-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Client filter logger
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Exposed so that the logging level within this package can be tailored differently to the default level when needed.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { LogLevel } from '@genesislcap/foundation-utils';
|
|
11
|
+
* import { logger as clientFilterLogger } from '@genesislcap/foundation-filters';
|
|
12
|
+
* clientFilterLogger.level = LogLevel.Error;
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export const logger = createLogger('foundation-filters');
|
|
18
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
2
|
+
import { logger } from './logger';
|
|
3
|
+
/**
|
|
4
|
+
* NodeEnv client filter function.
|
|
5
|
+
* @remarks
|
|
6
|
+
* This will return true when the current node env matches target parameters.
|
|
7
|
+
* @param envs - Environments to target.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export function nodeEnvFilter(envs) {
|
|
11
|
+
if (!envs) {
|
|
12
|
+
logger.warn('NodeEnv filter parameters must include envs.');
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return !!process.env.NODE_ENV && envs.includes(process.env.NODE_ENV);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Default NodeEnv DI implementation.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export class DefaultNodeEnv {
|
|
22
|
+
/** {@inheritDoc ClientFilter.filter} */
|
|
23
|
+
filter(params) {
|
|
24
|
+
return nodeEnvFilter(params === null || params === void 0 ? void 0 : params.envs);
|
|
25
|
+
}
|
|
26
|
+
/** {@inheritDoc NodeEnv.isDevelopment} */
|
|
27
|
+
get isDevelopment() {
|
|
28
|
+
return nodeEnvFilter(['development']);
|
|
29
|
+
}
|
|
30
|
+
/** {@inheritDoc NodeEnv.isTesting} */
|
|
31
|
+
get isTesting() {
|
|
32
|
+
return nodeEnvFilter(['testing', 'test']);
|
|
33
|
+
}
|
|
34
|
+
/** {@inheritDoc NodeEnv.isProduction} */
|
|
35
|
+
get isProduction() {
|
|
36
|
+
return nodeEnvFilter(['production']);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* NodeEnv DI key.
|
|
41
|
+
*
|
|
42
|
+
* @privateRemarks
|
|
43
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export const NodeEnv = DI.createInterface((x) => x.transient(DefaultNodeEnv));
|
|
48
|
+
//# sourceMappingURL=nodeEnv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeEnv.js","sourceRoot":"","sources":["../../src/nodeEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAAc;IAC1C,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;KACb;IACD,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACvE,CAAC;AAqDD;;;GAGG;AACH,MAAM,OAAO,cAAc;IACzB,wCAAwC;IACxC,MAAM,CAAC,MAAqB;QAC1B,OAAO,aAAa,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,0CAA0C;IAC1C,IAAI,aAAa;QACf,OAAO,aAAa,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,sCAAsC;IACtC,IAAI,SAAS;QACX,OAAO,aAAa,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,yCAAyC;IACzC,IAAI,YAAY;QACd,OAAO,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;IACvC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,CAAC,eAAe,CAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
2
|
+
import { logger } from './logger';
|
|
3
|
+
/**
|
|
4
|
+
* Percentage client filter function.
|
|
5
|
+
* @remarks
|
|
6
|
+
* This will return true a certain percentage of the time.
|
|
7
|
+
* @param percent - The percent of the time to pass, a numeric value between 0 and 1.
|
|
8
|
+
* @param random - Math.random() generated floating-point.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export function percentageFilter(percent, random = Math.random()) {
|
|
12
|
+
const withinRange = percent >= 0 && percent <= 1;
|
|
13
|
+
if (!withinRange) {
|
|
14
|
+
logger.warn('Percentage filter parameters must include a numeric percent between 0 and 1.');
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return random < percent;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Default Percentage DI implementation.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export class DefaultPercentage {
|
|
24
|
+
/** {@inheritDoc ClientFilter.filter} */
|
|
25
|
+
filter(params) {
|
|
26
|
+
return percentageFilter(params === null || params === void 0 ? void 0 : params.percent, params === null || params === void 0 ? void 0 : params.random);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Percentage DI key.
|
|
31
|
+
*
|
|
32
|
+
* @privateRemarks
|
|
33
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export const Percentage = DI.createInterface((x) => x.transient(DefaultPercentage));
|
|
38
|
+
//# sourceMappingURL=percentage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"percentage.js","sourceRoot":"","sources":["../../src/percentage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE;IACtE,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC5F,OAAO,IAAI,CAAC;KACb;IACD,OAAO,MAAM,GAAG,OAAO,CAAC;AAC1B,CAAC;AA4DD;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC5B,wCAAwC;IACxC,MAAM,CAAC,MAAwB;QAC7B,OAAO,gBAAgB,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,CAAC,CAAC;IAC3D,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC,eAAe,CAAa,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
2
|
+
import { logger } from './logger';
|
|
3
|
+
/**
|
|
4
|
+
* TimeWindow client filter function.
|
|
5
|
+
* @remarks
|
|
6
|
+
* This will return true between a certain time window. Start and end can be provided in any format recognized by the
|
|
7
|
+
* Date.parse() method.
|
|
8
|
+
*
|
|
9
|
+
* @param start - The start of the time window.
|
|
10
|
+
* @param end - The end of the time window.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export function timeWindowFilter(start, end) {
|
|
14
|
+
if (!start && !end) {
|
|
15
|
+
logger.warn('TimeWindow filter parameters must include start, end, or both.');
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
const now = new Date();
|
|
19
|
+
let result = true;
|
|
20
|
+
if (start) {
|
|
21
|
+
const startDate = new Date(start);
|
|
22
|
+
result = now >= startDate;
|
|
23
|
+
}
|
|
24
|
+
if (end && result) {
|
|
25
|
+
const endDate = new Date(end);
|
|
26
|
+
result = now < endDate;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Default TimeWindow DI implementation.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export class DefaultTimeWindow {
|
|
35
|
+
/** {@inheritDoc ClientFilter.filter} */
|
|
36
|
+
filter(params) {
|
|
37
|
+
return timeWindowFilter(params === null || params === void 0 ? void 0 : params.start, params === null || params === void 0 ? void 0 : params.end);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* TimeWindow DI key.
|
|
42
|
+
*
|
|
43
|
+
* @privateRemarks
|
|
44
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export const TimeWindow = DI.createInterface((x) => x.transient(DefaultTimeWindow));
|
|
49
|
+
//# sourceMappingURL=timeWindow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeWindow.js","sourceRoot":"","sources":["../../src/timeWindow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,GAAY;IAC3D,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE;QAClB,MAAM,CAAC,IAAI,CAAC,gEAAgE,CAAC,CAAC;QAC9E,OAAO,IAAI,CAAC;KACb;IACD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,KAAK,EAAE;QACT,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC;KAC3B;IACD,IAAI,GAAG,IAAI,MAAM,EAAE;QACjB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC;KACxB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAoED;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC5B,wCAAwC;IACxC,MAAM,CAAC,MAAwB;QAC7B,OAAO,gBAAgB,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAC,CAAC;IACtD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC,eAAe,CAAa,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
2
|
+
import { logger } from './logger';
|
|
3
|
+
/**
|
|
4
|
+
* URLTargeting client filter function.
|
|
5
|
+
* @remarks
|
|
6
|
+
* This will return true when the current URL matches on ANY of the parameters. If you wish to match on multiple
|
|
7
|
+
* parameters, consider chaining an array of urlTargeting filters together.
|
|
8
|
+
* @param url - A url.
|
|
9
|
+
* @param pattern - A regex.
|
|
10
|
+
* @param schemes - Schemes/protocols to target.
|
|
11
|
+
* @param hosts - Hosts to target.
|
|
12
|
+
* @param paths - Paths to target.
|
|
13
|
+
* @public
|
|
14
|
+
* @privateRemarks
|
|
15
|
+
* The pattern regex can cover everything here, but some devs will likely welcome the explicit arguments.
|
|
16
|
+
*/
|
|
17
|
+
export function urlTargetingFilter(url, pattern, schemes, hosts, paths) {
|
|
18
|
+
var _a;
|
|
19
|
+
if (!url) {
|
|
20
|
+
logger.warn('URLTargeting filter needs a url to filter on.');
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (!pattern && !schemes && !hosts && !paths) {
|
|
24
|
+
logger.warn('URLTargeting filter parameters must include pattern, schemes, hosts, or paths.');
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (pattern && pattern.test(url)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
let urlObj;
|
|
31
|
+
try {
|
|
32
|
+
urlObj = new URL(url);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (schemes && schemes.includes((_a = urlObj.protocol) === null || _a === void 0 ? void 0 : _a.slice(0, -1))) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (hosts && hosts.includes(urlObj.host)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return !!paths && paths.includes(urlObj.pathname);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Default URLTargeting DI implementation.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export class DefaultURLTargeting {
|
|
50
|
+
/** {@inheritDoc ClientFilter.filter} */
|
|
51
|
+
filter(params) {
|
|
52
|
+
return urlTargetingFilter(params === null || params === void 0 ? void 0 : params.url, params === null || params === void 0 ? void 0 : params.pattern, params === null || params === void 0 ? void 0 : params.schemes, params === null || params === void 0 ? void 0 : params.hosts, params === null || params === void 0 ? void 0 : params.paths);
|
|
53
|
+
}
|
|
54
|
+
/** {@inheritDoc URLTargeting.isSecure} */
|
|
55
|
+
isSecure(url) {
|
|
56
|
+
return urlTargetingFilter(url, null, ['https', 'wss']);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* URLTargeting DI key.
|
|
61
|
+
*
|
|
62
|
+
* @privateRemarks
|
|
63
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export const URLTargeting = DI.createInterface((x) => x.transient(DefaultURLTargeting));
|
|
68
|
+
//# sourceMappingURL=urlTargeting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlTargeting.js","sourceRoot":"","sources":["../../src/urlTargeting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,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AM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EACf,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,EACb,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CACd,CAAC;IACJ,CAAC;IAED,0CAA0C;IAC1C,QAAQ,CAAC,GAAG;QACV,OAAO,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC,eAAe,CAAe,CAAC,CAAC,EAAE,EAAE,CACjE,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACjC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
2
|
+
import UAParser from 'ua-parser-js';
|
|
3
|
+
import { logger } from './logger';
|
|
4
|
+
/**
|
|
5
|
+
* UserAgent client filter function.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* See {@link https://github.com/faisalman/ua-parser-js} for more information.
|
|
9
|
+
*
|
|
10
|
+
* @param browsers - Browser names to target.
|
|
11
|
+
* @param devices - Device types to target.
|
|
12
|
+
* @param oss - Operating system names to target.
|
|
13
|
+
* @param ua - User-agent string (required in nodejs environment).
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export function userAgentFilter(browsers, devices, oss, ua) {
|
|
17
|
+
if (!browsers && !devices && !oss) {
|
|
18
|
+
logger.warn('UserAgent filter parameters must include browsers, devices, oss, or all three.');
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const parser = new UAParser(ua);
|
|
22
|
+
const browser = browsers && parser.getBrowser();
|
|
23
|
+
if (browser && browser.name && browsers.includes(browser.name)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const device = devices && parser.getDevice();
|
|
27
|
+
if (device && device.type && devices.includes(device.type)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const os = oss && parser.getOS();
|
|
31
|
+
return !!os && !!os.name && oss.includes(os.name);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Default UserAgent DI implementation.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export class DefaultUserAgent {
|
|
38
|
+
/** {@inheritDoc ClientFilter.filter} */
|
|
39
|
+
filter(params) {
|
|
40
|
+
return userAgentFilter(params === null || params === void 0 ? void 0 : params.browsers, params === null || params === void 0 ? void 0 : params.devices, params === null || params === void 0 ? void 0 : params.oss, params === null || params === void 0 ? void 0 : params.ua);
|
|
41
|
+
}
|
|
42
|
+
/** {@inheritDoc UserAgent.isSafari} */
|
|
43
|
+
get isSafari() {
|
|
44
|
+
/**
|
|
45
|
+
* You can use pre-defined params to encapsulate common requests.
|
|
46
|
+
*/
|
|
47
|
+
return userAgentFilter(['Safari']);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* UserAgent DI key.
|
|
52
|
+
*
|
|
53
|
+
* @privateRemarks
|
|
54
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export const UserAgent = DI.createInterface((x) => x.transient(DefaultUserAgent));
|
|
59
|
+
//# sourceMappingURL=userAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userAgent.js","sourceRoot":"","sources":["../../src/userAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,4BAA4B,CAAC;AAChD,OAAO,QAAQ,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,QAAmB,EACnB,OAAkB,EAClB,GAAc,EACd,EAA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CAAC;IACrC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC,eAAe,CAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { __decorate, __param } from "tslib";
|
|
2
|
+
import { Auth } from '@genesislcap/foundation-comms';
|
|
3
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
4
|
+
import { logger } from './logger';
|
|
5
|
+
/**
|
|
6
|
+
* UserTargeting client filter function.
|
|
7
|
+
* @remarks
|
|
8
|
+
* This will return true when the current user matches on ANY of the parameters. If you wish to match on multiple
|
|
9
|
+
* parameters, consider chaining an array of userTargeting filters together.
|
|
10
|
+
* @param user - A user object.
|
|
11
|
+
* @param usernames - Usernames to target.
|
|
12
|
+
* @param profiles - Profiles to target.
|
|
13
|
+
* @param permissions - Permissions to target.
|
|
14
|
+
* @public
|
|
15
|
+
* @privateRemarks
|
|
16
|
+
* We could provide another parameter to indicate a complete match is required?
|
|
17
|
+
*/
|
|
18
|
+
export function userTargetingFilter(user, usernames, profiles, permissions) {
|
|
19
|
+
if (!user) {
|
|
20
|
+
logger.warn('UserTargeting filter needs a user to filter on.');
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
if (!usernames && !profiles && !permissions) {
|
|
24
|
+
logger.warn('UserTargeting filter parameters must include usernames, profiles, permissions, or all three.');
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (usernames && usernames.includes(user.username)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (profiles && profiles.some((p) => user.profiles.includes(p))) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return !!permissions && permissions.some((p) => user.permissions.includes(p));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Default UserTargeting DI implementation.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
let DefaultUserTargeting = class DefaultUserTargeting {
|
|
40
|
+
constructor(auth) {
|
|
41
|
+
this.auth = auth;
|
|
42
|
+
}
|
|
43
|
+
/** {@inheritDoc ClientFilter.filter} */
|
|
44
|
+
filter(params) {
|
|
45
|
+
return userTargetingFilter(this.auth.currentUser, params === null || params === void 0 ? void 0 : params.usernames, params === null || params === void 0 ? void 0 : params.profiles, params === null || params === void 0 ? void 0 : params.permissions);
|
|
46
|
+
}
|
|
47
|
+
/** {@inheritDoc UserTargeting.hasAdminProfile} */
|
|
48
|
+
get hasAdminProfile() {
|
|
49
|
+
/**
|
|
50
|
+
* This could simply be `return this.auth.currentUser.hasAdminProfile()`, but the purpose was to show how we
|
|
51
|
+
* might leverage the baseline filter function with pre-defined params to encapsulate common requests.
|
|
52
|
+
*/
|
|
53
|
+
return userTargetingFilter(this.auth.currentUser, undefined, ['ADMIN']);
|
|
54
|
+
}
|
|
55
|
+
/** {@inheritDoc UserTargeting.isLoggedIn} */
|
|
56
|
+
get isLoggedIn() {
|
|
57
|
+
return this.auth.isLoggedIn;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
DefaultUserTargeting = __decorate([
|
|
61
|
+
__param(0, Auth)
|
|
62
|
+
], DefaultUserTargeting);
|
|
63
|
+
export { DefaultUserTargeting };
|
|
64
|
+
/**
|
|
65
|
+
* UserTargeting DI key.
|
|
66
|
+
*
|
|
67
|
+
* @privateRemarks
|
|
68
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
|
69
|
+
*
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
export const UserTargeting = DI.createInterface((x) => x.transient(DefaultUserTargeting));
|
|
73
|
+
//# sourceMappingURL=userTargeting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userTargeting.js","sourceRoot":"","sources":["../../src/userTargeting.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,I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