1 |
|
2 | "use strict";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | exports.ActionCodeSettingsBuilder = void 0;
|
20 | var validator = require("../utils/validator");
|
21 | var error_1 = require("../utils/error");
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | var ActionCodeSettingsBuilder = (function () {
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function ActionCodeSettingsBuilder(actionCodeSettings) {
|
37 | if (!validator.isNonNullObject(actionCodeSettings)) {
|
38 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings" must be a non-null object.');
|
39 | }
|
40 | if (typeof actionCodeSettings.url === 'undefined') {
|
41 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.MISSING_CONTINUE_URI);
|
42 | }
|
43 | else if (!validator.isURL(actionCodeSettings.url)) {
|
44 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_CONTINUE_URI);
|
45 | }
|
46 | this.continueUrl = actionCodeSettings.url;
|
47 | if (typeof actionCodeSettings.handleCodeInApp !== 'undefined' &&
|
48 | !validator.isBoolean(actionCodeSettings.handleCodeInApp)) {
|
49 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings.handleCodeInApp" must be a boolean.');
|
50 | }
|
51 | this.canHandleCodeInApp = actionCodeSettings.handleCodeInApp || false;
|
52 | if (typeof actionCodeSettings.dynamicLinkDomain !== 'undefined' &&
|
53 | !validator.isNonEmptyString(actionCodeSettings.dynamicLinkDomain)) {
|
54 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_DYNAMIC_LINK_DOMAIN);
|
55 | }
|
56 | this.dynamicLinkDomain = actionCodeSettings.dynamicLinkDomain;
|
57 | if (typeof actionCodeSettings.iOS !== 'undefined') {
|
58 | if (!validator.isNonNullObject(actionCodeSettings.iOS)) {
|
59 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings.iOS" must be a valid non-null object.');
|
60 | }
|
61 | else if (typeof actionCodeSettings.iOS.bundleId === 'undefined') {
|
62 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.MISSING_IOS_BUNDLE_ID);
|
63 | }
|
64 | else if (!validator.isNonEmptyString(actionCodeSettings.iOS.bundleId)) {
|
65 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings.iOS.bundleId" must be a valid non-empty string.');
|
66 | }
|
67 | this.ibi = actionCodeSettings.iOS.bundleId;
|
68 | }
|
69 | if (typeof actionCodeSettings.android !== 'undefined') {
|
70 | if (!validator.isNonNullObject(actionCodeSettings.android)) {
|
71 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings.android" must be a valid non-null object.');
|
72 | }
|
73 | else if (typeof actionCodeSettings.android.packageName === 'undefined') {
|
74 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.MISSING_ANDROID_PACKAGE_NAME);
|
75 | }
|
76 | else if (!validator.isNonEmptyString(actionCodeSettings.android.packageName)) {
|
77 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings.android.packageName" must be a valid non-empty string.');
|
78 | }
|
79 | else if (typeof actionCodeSettings.android.minimumVersion !== 'undefined' &&
|
80 | !validator.isNonEmptyString(actionCodeSettings.android.minimumVersion)) {
|
81 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings.android.minimumVersion" must be a valid non-empty string.');
|
82 | }
|
83 | else if (typeof actionCodeSettings.android.installApp !== 'undefined' &&
|
84 | !validator.isBoolean(actionCodeSettings.android.installApp)) {
|
85 | throw new error_1.FirebaseAuthError(error_1.AuthClientErrorCode.INVALID_ARGUMENT, '"ActionCodeSettings.android.installApp" must be a valid boolean.');
|
86 | }
|
87 | this.apn = actionCodeSettings.android.packageName;
|
88 | this.amv = actionCodeSettings.android.minimumVersion;
|
89 | this.installApp = actionCodeSettings.android.installApp || false;
|
90 | }
|
91 | }
|
92 | |
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | ActionCodeSettingsBuilder.prototype.buildRequest = function () {
|
99 | var request = {
|
100 | continueUrl: this.continueUrl,
|
101 | canHandleCodeInApp: this.canHandleCodeInApp,
|
102 | dynamicLinkDomain: this.dynamicLinkDomain,
|
103 | androidPackageName: this.apn,
|
104 | androidMinimumVersion: this.amv,
|
105 | androidInstallApp: this.installApp,
|
106 | iOSBundleId: this.ibi,
|
107 | };
|
108 |
|
109 | for (var key in request) {
|
110 | if (Object.prototype.hasOwnProperty.call(request, key)) {
|
111 | if (typeof request[key] === 'undefined' || request[key] === null) {
|
112 | delete request[key];
|
113 | }
|
114 | }
|
115 | }
|
116 | return request;
|
117 | };
|
118 | return ActionCodeSettingsBuilder;
|
119 | }());
|
120 | exports.ActionCodeSettingsBuilder = ActionCodeSettingsBuilder;
|