kinvey-js-sdk
Advanced tools
Comparing version 6.0.0-next.0 to 6.0.0-next.1
@@ -7,2 +7,3 @@ import { Acl } from './acl'; | ||
import * as Files from './files'; | ||
import * as MFA from './mfa'; | ||
import { init, initialize } from './init'; | ||
@@ -23,2 +24,2 @@ import { Kmd } from './kmd'; | ||
}; | ||
export { init, initialize, getAppVersion, setAppVersion, logger, ping, Acl, Aggregation, CustomEndpoint, DataStore, DataStoreType, Errors, Files, Kmd, Kmd as Metadata, Query, User, AuthorizationGrant }; | ||
export { init, initialize, getAppVersion, setAppVersion, logger, ping, Acl, Aggregation, CustomEndpoint, DataStore, DataStoreType, Errors, Files, Kmd, Kmd as Metadata, Query, User, AuthorizationGrant, MFA }; |
@@ -21,2 +21,4 @@ "use strict"; | ||
exports.Files = Files; | ||
var MFA = __importStar(require("./mfa")); | ||
exports.MFA = MFA; | ||
var init_1 = require("./init"); | ||
@@ -23,0 +25,0 @@ exports.init = init_1.init; |
@@ -67,5 +67,5 @@ "use strict"; | ||
} | ||
return 5; | ||
return 6; | ||
} | ||
exports.getApiVersion = getApiVersion; | ||
//# sourceMappingURL=kinvey.js.map |
@@ -93,3 +93,3 @@ "use strict"; | ||
} | ||
function completeMFALoginRetryable(mfaComplete, context) { | ||
function completeMFALoginRetryable(mfaComplete, context, maxRetriesCount) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -100,2 +100,5 @@ var errMsgNoCode, errMsgTrustDevice, mfaCompleteResult, trustDevice, mfaData, err_1; | ||
case 0: | ||
if (context.retries >= maxRetriesCount) { | ||
throw new kinvey_1.KinveyError('Max retries count exceeded.'); | ||
} | ||
errMsgNoCode = 'MFA code is missing.'; | ||
@@ -124,3 +127,3 @@ errMsgTrustDevice = 'trustDevice should be boolean.'; | ||
context.error = err_1; // eslint-disable-line no-param-reassign | ||
return [2 /*return*/, completeMFALoginRetryable(mfaComplete, context)]; | ||
return [2 /*return*/, completeMFALoginRetryable(mfaComplete, context, maxRetriesCount)]; | ||
case 5: return [2 /*return*/]; | ||
@@ -193,3 +196,3 @@ } | ||
_b.sent(); | ||
return [4 /*yield*/, completeMFALoginRetryable(mfaComplete, context)]; | ||
return [4 /*yield*/, completeMFALoginRetryable(mfaComplete, context, 10)]; | ||
case 13: | ||
@@ -202,5 +205,8 @@ mfaResult = _b.sent(); | ||
_b.label = 15; | ||
case 15: return [4 /*yield*/, http_1.setSession(mfaResult.user)]; | ||
case 15: return [4 /*yield*/, http_1.removeMFASessionToken()]; | ||
case 16: | ||
_b.sent(); | ||
return [4 /*yield*/, http_1.setSession(mfaResult.user)]; | ||
case 17: | ||
_b.sent(); | ||
return [2 /*return*/, new user_1.User(mfaResult.user)]; | ||
@@ -207,0 +213,0 @@ } |
@@ -9,2 +9,24 @@ import { Acl } from '../acl'; | ||
} | ||
export interface MFAAuthenticator { | ||
id: string; | ||
name: string; | ||
type: string; | ||
config?: object; | ||
} | ||
export interface CreateMFAAuthenticatorResult { | ||
authenticator: MFAAuthenticator; | ||
recoveryCodes?: string[]; | ||
} | ||
export declare enum MFAAuthenticatorType { | ||
TOTP = "totp" | ||
} | ||
export interface NewMFAAuthenticator { | ||
name: string; | ||
type?: MFAAuthenticatorType; | ||
} | ||
export interface VerifyContext { | ||
retries: number; | ||
authenticator: MFAAuthenticator; | ||
error?: any; | ||
} | ||
export declare class User { | ||
@@ -39,3 +61,9 @@ data: UserData; | ||
}): Promise<boolean>; | ||
_cleanup(kinveyRequest: any, operationName: any): Promise<this>; | ||
_verifyAuthenticatorRetryable(verify: (authenticator: MFAAuthenticator, context: VerifyContext) => Promise<string>, context: VerifyContext): Promise<any>; | ||
createAuthenticator(newAuthenticator: NewMFAAuthenticator, verify: (authenticator: MFAAuthenticator, context: VerifyContext) => Promise<string>): Promise<CreateMFAAuthenticatorResult>; | ||
listAuthenticators(): Promise<MFAAuthenticator[]>; | ||
removeAuthenticator(id: string): Promise<void>; | ||
listRecoveryCodes(): Promise<string[]>; | ||
regenerateRecoveryCodes(): Promise<string[]>; | ||
_cleanup(kinveyRequest: any, operationName: any, cleanEntireSessionStore?: boolean): Promise<this>; | ||
logout(options?: { | ||
@@ -42,0 +70,0 @@ timeout?: number; |
@@ -42,2 +42,4 @@ "use strict"; | ||
var isArray_1 = __importDefault(require("lodash/isArray")); | ||
var pick_1 = __importDefault(require("lodash/pick")); | ||
var defaults_1 = __importDefault(require("lodash/defaults")); | ||
var acl_1 = require("../acl"); | ||
@@ -53,2 +55,6 @@ var kmd_1 = require("../kmd"); | ||
var signup_1 = require("./signup"); | ||
var MFAAuthenticatorType; | ||
(function (MFAAuthenticatorType) { | ||
MFAAuthenticatorType["TOTP"] = "totp"; | ||
})(MFAAuthenticatorType = exports.MFAAuthenticatorType || (exports.MFAAuthenticatorType = {})); | ||
var User = /** @class */ (function () { | ||
@@ -310,4 +316,146 @@ function User(data) { | ||
}; | ||
User.prototype._cleanup = function (kinveyRequest, operationName) { | ||
User.prototype._verifyAuthenticatorRetryable = function (verify, context) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var code, request, data, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, verify(context.authenticator, context)]; | ||
case 1: | ||
code = _a.sent(); | ||
if (code == null) { | ||
throw new kinvey_1.KinveyError('MFA code is missing.'); | ||
} | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 5]); | ||
request = new http_1.KinveyHttpRequest({ | ||
method: http_1.HttpRequestMethod.POST, | ||
auth: http_1.KinveyHttpAuth.SessionOrMaster, | ||
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/authenticators/" + context.authenticator.id + "/verify"), | ||
body: { code: code }, | ||
}); | ||
return [4 /*yield*/, request.execute()]; | ||
case 3: | ||
data = (_a.sent()).data; | ||
return [2 /*return*/, data]; | ||
case 4: | ||
err_1 = _a.sent(); | ||
context.retries += 1; // eslint-disable-line no-param-reassign | ||
context.error = err_1; // eslint-disable-line no-param-reassign | ||
return [2 /*return*/, this._verifyAuthenticatorRetryable(verify, context)]; | ||
case 5: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
User.prototype.createAuthenticator = function (newAuthenticator, verify) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var request, authenticator, verifyResult; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!verify) { | ||
throw new kinvey_1.KinveyError('Function to verify authenticator is missing.'); | ||
} | ||
request = new http_1.KinveyHttpRequest({ | ||
method: http_1.HttpRequestMethod.POST, | ||
auth: http_1.KinveyHttpAuth.SessionOrMaster, | ||
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/authenticators"), | ||
body: defaults_1.default(newAuthenticator, { type: MFAAuthenticatorType.TOTP }), | ||
}); | ||
return [4 /*yield*/, request.execute()]; | ||
case 1: | ||
authenticator = (_a.sent()).data; | ||
return [4 /*yield*/, this._verifyAuthenticatorRetryable(verify, { authenticator: authenticator, retries: 0 })]; | ||
case 2: | ||
verifyResult = _a.sent(); | ||
return [2 /*return*/, { | ||
authenticator: pick_1.default(authenticator, ['id', 'name', 'type', 'config']), | ||
recoveryCodes: verifyResult.recoveryCodes, | ||
}]; | ||
} | ||
}); | ||
}); | ||
}; | ||
User.prototype.listAuthenticators = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var request, data; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
request = new http_1.KinveyHttpRequest({ | ||
method: http_1.HttpRequestMethod.GET, | ||
auth: http_1.KinveyHttpAuth.SessionOrMaster, | ||
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/authenticators"), | ||
}); | ||
return [4 /*yield*/, request.execute()]; | ||
case 1: | ||
data = (_a.sent()).data; | ||
return [2 /*return*/, data.map(function (a) { | ||
return { id: a.id, name: a.name, type: a.type }; | ||
})]; | ||
} | ||
}); | ||
}); | ||
}; | ||
User.prototype.removeAuthenticator = function (id) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var request; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
request = new http_1.KinveyHttpRequest({ | ||
method: http_1.HttpRequestMethod.DELETE, | ||
auth: http_1.KinveyHttpAuth.SessionOrMaster, | ||
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/authenticators/" + id + "/"), | ||
}); | ||
return [4 /*yield*/, request.execute()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
User.prototype.listRecoveryCodes = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var request, data; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
request = new http_1.KinveyHttpRequest({ | ||
method: http_1.HttpRequestMethod.GET, | ||
auth: http_1.KinveyHttpAuth.SessionOrMaster, | ||
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/recovery-codes"), | ||
}); | ||
return [4 /*yield*/, request.execute()]; | ||
case 1: | ||
data = (_a.sent()).data; | ||
return [2 /*return*/, data.recoveryCodes]; | ||
} | ||
}); | ||
}); | ||
}; | ||
User.prototype.regenerateRecoveryCodes = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var request, data; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
request = new http_1.KinveyHttpRequest({ | ||
method: http_1.HttpRequestMethod.POST, | ||
auth: http_1.KinveyHttpAuth.SessionOrMaster, | ||
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/recovery-codes"), | ||
}); | ||
return [4 /*yield*/, request.execute()]; | ||
case 1: | ||
data = (_a.sent()).data; | ||
return [2 /*return*/, data.recoveryCodes]; | ||
} | ||
}); | ||
}); | ||
}; | ||
User.prototype._cleanup = function (kinveyRequest, operationName, cleanEntireSessionStore) { | ||
if (cleanEntireSessionStore === void 0) { cleanEntireSessionStore = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var error_1; | ||
@@ -337,10 +485,18 @@ return __generator(this, function (_a) { | ||
_a.sent(); | ||
return [4 /*yield*/, cache_1.QueryCache.clear()]; | ||
if (!cleanEntireSessionStore) return [3 /*break*/, 9]; | ||
return [4 /*yield*/, http_1.removeMFASessionToken()]; | ||
case 7: | ||
_a.sent(); | ||
return [4 /*yield*/, cache_1.SyncCache.clear()]; | ||
return [4 /*yield*/, http_1.removeDeviceToken(this.data.username)]; | ||
case 8: | ||
_a.sent(); | ||
_a.label = 9; | ||
case 9: return [4 /*yield*/, cache_1.QueryCache.clear()]; | ||
case 10: | ||
_a.sent(); | ||
return [4 /*yield*/, cache_1.SyncCache.clear()]; | ||
case 11: | ||
_a.sent(); | ||
return [4 /*yield*/, cache_1.DataStoreCache.clear()]; | ||
case 9: | ||
case 12: | ||
_a.sent(); | ||
@@ -376,3 +532,3 @@ return [2 /*return*/, this]; | ||
}); | ||
return [2 /*return*/, this._cleanup(request, 'Tokens invalidation')]; | ||
return [2 /*return*/, this._cleanup(request, 'Tokens invalidation', true)]; | ||
}); | ||
@@ -379,0 +535,0 @@ }); |
{ | ||
"name": "kinvey-js-sdk", | ||
"description": "Kinvey JavaScript SDK for JavaScript applications.", | ||
"version": "6.0.0-next.0", | ||
"version": "6.0.0-next.1", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
746732
340
11623