@singularsystems/neo-core 1.0.4 → 1.0.5
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/Model/IModelBase.d.ts +3 -0
- package/dist/Model/ModelBase.d.ts +7 -2
- package/dist/Model/ModelBase.js +8 -2
- package/dist/Model/NeoTypeInfo.js +8 -6
- package/dist/Security/IAuthenticationService.d.ts +0 -2
- package/dist/Security/Oidc/OidcAuthService.d.ts +3 -1
- package/dist/Security/Oidc/OidcAuthService.js +18 -5
- package/dist/Validation/ValidationRules.d.ts +5 -3
- package/dist/Validation/ValidationRules.js +4 -2
- package/package.json +1 -1
|
@@ -46,6 +46,9 @@ export type PartialPlainNonTrackedObject<T> = PartialPlainObject<T> & {
|
|
|
46
46
|
export interface NeoModelConstructor extends Function {
|
|
47
47
|
neo: NeoTypeInfo;
|
|
48
48
|
}
|
|
49
|
+
export interface NeoModelConstructorInternal extends Function {
|
|
50
|
+
addBusinessRules?(validationRules: ValidationRules<IModelBase>): void;
|
|
51
|
+
}
|
|
49
52
|
export interface IMakeBindableOptions {
|
|
50
53
|
/**
|
|
51
54
|
* Specifies whether properties should be observable
|
|
@@ -79,10 +79,15 @@ export default abstract class ModelBase extends BindableBase implements IModelBa
|
|
|
79
79
|
* @param shouldSerialise The value determined by the serialiser.
|
|
80
80
|
*/
|
|
81
81
|
protected canSerialise(shouldSerialise: boolean): boolean;
|
|
82
|
+
/** @deprecated Make your addBusinessRules method `static`. E.g.
|
|
83
|
+
* ```
|
|
84
|
+
* protected static addBusinessRules(rules: ValidationRules<MyType>) {
|
|
85
|
+
* ``` */
|
|
86
|
+
protected addBusinessRules(validationRules: ValidationRules<this>): void;
|
|
82
87
|
/**
|
|
83
|
-
* Add custom business rules
|
|
88
|
+
* Add custom business rules for this type.
|
|
84
89
|
*/
|
|
85
|
-
protected addBusinessRules(
|
|
90
|
+
protected static addBusinessRules(rules: ValidationRules<ModelBase>): void;
|
|
86
91
|
/** The server side type name used to find this type. Include the namespace if there is more than one type with the same name. */
|
|
87
92
|
static typeName: string | null;
|
|
88
93
|
}
|
package/dist/Model/ModelBase.js
CHANGED
|
@@ -142,10 +142,16 @@ var ModelBase = /** @class */ (function (_super) {
|
|
|
142
142
|
ModelBase.prototype.canSerialise = function (shouldSerialise) {
|
|
143
143
|
return shouldSerialise;
|
|
144
144
|
};
|
|
145
|
+
/** @deprecated Make your addBusinessRules method `static`. E.g.
|
|
146
|
+
* ```
|
|
147
|
+
* protected static addBusinessRules(rules: ValidationRules<MyType>) {
|
|
148
|
+
* ``` */
|
|
149
|
+
ModelBase.prototype.addBusinessRules = function (validationRules) {
|
|
150
|
+
};
|
|
145
151
|
/**
|
|
146
|
-
* Add custom business rules
|
|
152
|
+
* Add custom business rules for this type.
|
|
147
153
|
*/
|
|
148
|
-
ModelBase.
|
|
154
|
+
ModelBase.addBusinessRules = function (rules) {
|
|
149
155
|
};
|
|
150
156
|
/** The server side type name used to find this type. Include the namespace if there is more than one type with the same name. */
|
|
151
157
|
ModelBase.typeName = null;
|
|
@@ -125,22 +125,24 @@ var NeoTypeInfo = /** @class */ (function () {
|
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
NeoTypeInfo.prototype.addRules = function (instance) {
|
|
128
|
-
|
|
128
|
+
var _a;
|
|
129
|
+
var addRulesMethod = (_a = this.objectConstructor.addBusinessRules) !== null && _a !== void 0 ? _a : instance.addBusinessRules;
|
|
130
|
+
if (addRulesMethod !== undefined) {
|
|
129
131
|
var validationRules = new ValidationRules();
|
|
130
|
-
|
|
132
|
+
addRulesMethod(validationRules);
|
|
131
133
|
if (validationRules.rules.some(function (c) { return c instanceof CallbackRule && c.hasArrowFunction; })) {
|
|
132
134
|
console.error("Warning: ".concat(this.objectConstructor.name, " has rules which have been added using an arrow function."));
|
|
133
135
|
}
|
|
134
136
|
var modelProxy = new ModelProxy(instance);
|
|
135
|
-
for (var _i = 0,
|
|
136
|
-
var rule =
|
|
137
|
+
for (var _i = 0, _b = validationRules.rules; _i < _b.length; _i++) {
|
|
138
|
+
var rule = _b[_i];
|
|
137
139
|
var properties = rule.getDisplayProperties(this.propertyMap);
|
|
138
140
|
if (properties === undefined && rule instanceof ExpressionRule) {
|
|
139
141
|
properties = modelProxy.tryExtractProperties(rule);
|
|
140
142
|
}
|
|
141
143
|
if (properties && properties.length) {
|
|
142
|
-
for (var
|
|
143
|
-
var property = properties_1[
|
|
144
|
+
for (var _c = 0, properties_1 = properties; _c < properties_1.length; _c++) {
|
|
145
|
+
var property = properties_1[_c];
|
|
144
146
|
property.rules.push(rule);
|
|
145
147
|
}
|
|
146
148
|
}
|
|
@@ -26,8 +26,6 @@ export default interface IAuthenticationService {
|
|
|
26
26
|
tryCompleteSignIn(): Promise<ISignInResult>;
|
|
27
27
|
signinSilent(): Promise<any>;
|
|
28
28
|
endSignInSilent(): Promise<any>;
|
|
29
|
-
/** Clears the user locally */
|
|
30
|
-
signOutLocal(): void;
|
|
31
29
|
beginSignOut(): void;
|
|
32
30
|
endSignOut(): Promise<any>;
|
|
33
31
|
/** Returns true if there is a user, and the token has not expired */
|
|
@@ -11,6 +11,7 @@ export default abstract class OidcAuthService<TUser extends OidcUser = OidcUser>
|
|
|
11
11
|
protected userManager: IUserManager;
|
|
12
12
|
private axios;
|
|
13
13
|
private _user;
|
|
14
|
+
private isRedirecting;
|
|
14
15
|
private afterUserLoadedPromise;
|
|
15
16
|
/**
|
|
16
17
|
* Creates an Oidc auth service
|
|
@@ -18,6 +19,7 @@ export default abstract class OidcAuthService<TUser extends OidcUser = OidcUser>
|
|
|
18
19
|
* @param user User which existed in storage at startup
|
|
19
20
|
*/
|
|
20
21
|
constructor(userManager: IUserManager, axios: AxiosInstance);
|
|
22
|
+
isSigningOut: boolean;
|
|
21
23
|
loadUserFromToken(): Promise<TUser | null>;
|
|
22
24
|
loadUserFromSession(): Promise<TUser | null>;
|
|
23
25
|
ensureSignedIn(redirectLocal?: string): boolean;
|
|
@@ -45,7 +47,7 @@ export default abstract class OidcAuthService<TUser extends OidcUser = OidcUser>
|
|
|
45
47
|
signinSilent(): Promise<IOidcUser | null>;
|
|
46
48
|
beginSignOut(): void;
|
|
47
49
|
endSignOut(): Promise<any>;
|
|
48
|
-
signOutLocal
|
|
50
|
+
private signOutLocal;
|
|
49
51
|
get user(): TUser | null;
|
|
50
52
|
get isAuthenticated(): boolean;
|
|
51
53
|
static createIdentityServerMetadata(identityServerUrl: string): {
|
|
@@ -18,6 +18,8 @@ var OidcAuthService = /** @class */ (function () {
|
|
|
18
18
|
this.userManager = userManager;
|
|
19
19
|
this.axios = axios;
|
|
20
20
|
this._user = null;
|
|
21
|
+
this.isRedirecting = false;
|
|
22
|
+
this.isSigningOut = false;
|
|
21
23
|
this.userManager = userManager;
|
|
22
24
|
this.userManager.events.addUserLoaded(this.onUserLoaded.bind(this));
|
|
23
25
|
this.userManager.events.addUserUnloaded(this.onUserUnloaded.bind(this));
|
|
@@ -64,7 +66,11 @@ var OidcAuthService = /** @class */ (function () {
|
|
|
64
66
|
* @param redirectPath Local path to redirect to once login is complete.
|
|
65
67
|
*/
|
|
66
68
|
OidcAuthService.prototype.beginSignIn = function (redirectPath) {
|
|
67
|
-
|
|
69
|
+
if (!this.isRedirecting) {
|
|
70
|
+
this.isRedirecting = true;
|
|
71
|
+
return this.userManager.signinRedirect({ state: redirectPath });
|
|
72
|
+
}
|
|
73
|
+
return Promise.resolve();
|
|
68
74
|
};
|
|
69
75
|
;
|
|
70
76
|
/**
|
|
@@ -77,6 +83,7 @@ var OidcAuthService = /** @class */ (function () {
|
|
|
77
83
|
switch (_a.label) {
|
|
78
84
|
case 0:
|
|
79
85
|
_a.trys.push([0, 2, , 3]);
|
|
86
|
+
this.isRedirecting = false;
|
|
80
87
|
return [4 /*yield*/, this.userManager.signinRedirectCallback()];
|
|
81
88
|
case 1:
|
|
82
89
|
user = _a.sent();
|
|
@@ -168,14 +175,20 @@ var OidcAuthService = /** @class */ (function () {
|
|
|
168
175
|
return this.userManager.signinSilent();
|
|
169
176
|
};
|
|
170
177
|
OidcAuthService.prototype.beginSignOut = function () {
|
|
171
|
-
if (this.
|
|
172
|
-
|
|
173
|
-
|
|
178
|
+
if (!this.isRedirecting) {
|
|
179
|
+
if (this._user) {
|
|
180
|
+
this.isRedirecting = true;
|
|
181
|
+
this.isSigningOut = true;
|
|
182
|
+
this.userManager.signoutRedirect({ id_token_hint: this._user.userData.id_token });
|
|
183
|
+
this.signOutLocal();
|
|
184
|
+
}
|
|
185
|
+
this.userManager.clearStaleState();
|
|
174
186
|
}
|
|
175
|
-
this.userManager.clearStaleState();
|
|
176
187
|
};
|
|
177
188
|
;
|
|
178
189
|
OidcAuthService.prototype.endSignOut = function () {
|
|
190
|
+
this.isRedirecting = false;
|
|
191
|
+
this.isSigningOut = false;
|
|
179
192
|
return this.userManager.signoutRedirectCallback();
|
|
180
193
|
};
|
|
181
194
|
;
|
|
@@ -5,10 +5,12 @@ export declare class ValidationRules<T extends IModelBase> {
|
|
|
5
5
|
rules: CustomRule<T>[];
|
|
6
6
|
/**
|
|
7
7
|
* Registers a custom rule.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* - Pass in the address of a function: `add(MyType.prototype.myRule)`
|
|
9
|
+
* - or pass an anonymous function: `add(function(context) {})`
|
|
10
|
+
*
|
|
11
|
+
* **NOTE: Do not use `.bind(this)`, and do not use an arrow function**.
|
|
10
12
|
*/
|
|
11
|
-
add(ruleFunction: (context: IRuleContext) => void): ICustomRule<T>;
|
|
13
|
+
add(ruleFunction: (this: T, context: IRuleContext) => void): ICustomRule<T>;
|
|
12
14
|
failWhen(failCondition: RuleExpression<T>, errorTextExpression: ErrorExpression<T>): IExpressionRule<T>;
|
|
13
15
|
failWhen(failCondition: RuleExpression<T>, errorText: string): IExpressionRule<T>;
|
|
14
16
|
warnWhen(condition: RuleExpression<T>, warningTextExpression: ErrorExpression<T>): IExpressionRule<T>;
|
|
@@ -6,8 +6,10 @@ var ValidationRules = /** @class */ (function () {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Registers a custom rule.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* - Pass in the address of a function: `add(MyType.prototype.myRule)`
|
|
10
|
+
* - or pass an anonymous function: `add(function(context) {})`
|
|
11
|
+
*
|
|
12
|
+
* **NOTE: Do not use `.bind(this)`, and do not use an arrow function**.
|
|
11
13
|
*/
|
|
12
14
|
ValidationRules.prototype.add = function (ruleFunction) {
|
|
13
15
|
var rule = new CallbackRule(ruleFunction);
|