@tonysamperi/ts-mapi-core 2.0.0-beta.3 → 2.0.0-beta.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/changelog.md +8 -1
- package/dist/cjs/firebase.cjs +1 -1
- package/dist/cjs/firebase.cjs.map +1 -1
- package/dist/cjs/firebase.d.cts +2 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +128 -139
- package/dist/cjs/rxjs.cjs +1 -1
- package/dist/cjs/rxjs.cjs.map +1 -1
- package/dist/cjs/rxjs.d.cts +1 -1
- package/dist/cjs/smp-firebase-errors.enum-BlzgwNdc.d.cts +25 -0
- package/dist/cjs/{smp-generic-response-base.interface-D0jHrkjw.d.cts → smp-generic-response-base.interface-C0On2LBc.d.cts} +1 -1
- package/dist/cjs/zod.cjs +1 -1
- package/dist/cjs/zod.cjs.map +1 -1
- package/dist/cjs/zod.d.cts +9 -9
- package/dist/esm/firebase.d.ts +2 -1
- package/dist/esm/firebase.js +1 -1
- package/dist/esm/index.d.ts +128 -139
- package/dist/esm/index.js +1 -1
- package/dist/esm/rxjs.d.ts +1 -1
- package/dist/esm/rxjs.js +1 -1
- package/dist/esm/smp-firebase-errors.enum-BlzgwNdc.d.ts +25 -0
- package/dist/esm/{smp-generic-response-base.interface-D0jHrkjw.d.ts → smp-generic-response-base.interface-C0On2LBc.d.ts} +1 -1
- package/dist/esm/zod.d.ts +9 -9
- package/dist/esm/zod.js +1 -1
- package/package.json +7 -2
- package/dist/cjs/smp-social-sign-in-ux-modes.enum-Cw9H3EqT.d.cts +0 -12
- package/dist/esm/smp-social-sign-in-ux-modes.enum-Cw9H3EqT.d.ts +0 -12
package/dist/esm/firebase.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SmpLoggerMethods } from '@tonysamperi/logger';
|
|
2
2
|
import { FirebaseOptions, FirebaseApp } from 'firebase/app';
|
|
3
3
|
import { User, Auth, AuthProvider, ActionCodeInfo, UserCredential, IdTokenResult } from 'firebase/auth';
|
|
4
|
-
import { S as SmpSocialSignInKeys, a as SmpSocialSignInUxModes } from './smp-
|
|
4
|
+
import { S as SmpSocialSignInKeys, a as SmpSocialSignInUxModes } from './smp-firebase-errors.enum-BlzgwNdc.js';
|
|
5
|
+
export { b as SmpFirebaseErrors } from './smp-firebase-errors.enum-BlzgwNdc.js';
|
|
5
6
|
|
|
6
7
|
interface SmpFirebaseServiceConfig {
|
|
7
8
|
enabledSocials?: SmpSocialSignInKeys[];
|
package/dist/esm/firebase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as s,b as o,c as n}from"./chunk-DIVAYUSN.js";import{a}from"./chunk-EI7MMDWY.js";import{SmpLoggerMethods as
|
|
1
|
+
import{a as s,b as o,c as n}from"./chunk-DIVAYUSN.js";import{a}from"./chunk-EI7MMDWY.js";import{SmpLoggerMethods as g}from"@tonysamperi/logger";import{getApps as d,initializeApp as c}from"firebase/app";import{browserLocalPersistence as u,browserSessionPersistence as p,EmailAuthProvider as _,FacebookAuthProvider as m,GoogleAuthProvider as f,OAuthProvider as P,checkActionCode as U,confirmPasswordReset as E,fetchSignInMethodsForEmail as b,getAuth as w,getRedirectResult as S,reauthenticateWithCredential as I,sendEmailVerification as F,sendPasswordResetEmail as A,setPersistence as C,signInWithCustomToken as v,signInWithEmailAndPassword as R,signInWithPopup as L,signInWithRedirect as O,signOut as T,updatePassword as k,updateProfile as x}from"firebase/auth";var l=class h{static{a(this,"SmpFirebaseService")}static get INSTANCE(){if(!(this._instance instanceof h))throw Error(`${this.constructor.name} instance doesn't exist! Call ${this.constructor.name}.init first!`);return this._instance}static _instance;get config(){return this._config}get enabledSocials(){return this._enabledSocials}get loggedUser(){return this._loggedUser||(this._loggedUser=this._readStoredUser()),this._auth.currentUser||this._loggedUser||void 0}get providersRelation(){return{"facebook.com":s.FACEBOOK,"google.com":s.GOOGLE,"apple.com":s.APPLE}}get socialLoginUXMode(){return this._socialLoginUxMode}get storedUserKey(){return"firebaseUser"}get _auth(){return w(this._app)}_app;_config;_enabledSocials=[];_loggedUser;_logger;_popupErrors=0;_popupFallsBackToRedirect;_providers;_socialLoginUxMode=o.POPUP;constructor(e,t){this._config=e,this._enabledSocials=t.enabledSocials||[],this._socialLoginUxMode=t.socialLoginUxMode||o.POPUP,this._popupFallsBackToRedirect=!!t.popupFallsBackToRedirect,this._buildProviders(),this._logger=t.logger||new g,this._app=d().length?d()[0]:c(e),this._watchAuthState()}static init(e,t){return this._instance||(this._instance=new h(e,t)),this._instance}addAuthStateChangedCallback(e){return this._auth.onAuthStateChanged(t=>{e(t||this.loggedUser||null)})}checkActionCode(e){return U(this._auth,e)}confirmPasswordReset(e,t){return E(this._auth,e,t)}fetchSignInMethodsForEmail(e){return b(this._auth,e).then(t=>t.map(r=>this.providersRelation[r]||r))}getRedirectResult(){return S(this._auth).catch(async e=>(await this._expandDifferentCredential(e),Promise.reject(e)))}initAppCheck(){}sendEmailVerification(e){if(!this.loggedUser)throw Error("Firebase: user is not logged!");return F(this.loggedUser,e?{url:e}:void 0)}sendPasswordResetEmail(e,t){return A(this._auth,e,{url:t})}setPersistence(e){return C(this._auth,e?u:p)}signInWithCustomToken(e){return v(this._auth,e)}signInWithEmailAndPassword(e,t){return R(this._auth,e,t).then(async r=>r.user)}signInWithSocialProvider(e){if(!this._providers[e])throw Error(`Firebase: invalid social key provided! Expected one of ${this.enabledSocials}, got ${e}`);return this._signInWithProvider(this._providers[e])}signOut(){return T(this._auth)}updatePassword(e,t){if(!this.loggedUser)throw Error("Firebase: user is not logged!");let r=_.credential(this.loggedUser.email,e);return I(this.loggedUser,r).then(()=>k(this.loggedUser,t))}updateUserProfile(e){if(!this.loggedUser)throw Error("Firebase: user is not logged!");return x(this.loggedUser,e)}async verifyIdToken(){return this._auth.currentUser?.getIdTokenResult()}_buildProviders(){this._providers=this._enabledSocials.reduce((e,t)=>(t in e&&(e[t]=e[t]),e),{[s.APPLE]:new P("apple.com"),[s.FACEBOOK]:new m().setCustomParameters({prompt:"select_account"}),[s.GOOGLE]:new f().setCustomParameters({prompt:"select_account"})})}async _expandDifferentCredential(e){if(e?.code===n.DIFFERENT_CREDENTIAL){let t=await this.fetchSignInMethodsForEmail(e.customData.email);throw e.code=n["DIFFERENT_CREDENTIAL_"+t[0]],e}}_readStoredUser(){try{let e=localStorage.getItem(this.storedUserKey);if(e){this._logger?.debug("Firebase: found local user",e);let t=JSON.parse(e);return{...t,getIdToken:a(()=>Promise.resolve(t.stsTokenManager.accessToken),"getIdToken")}}}catch(e){this._logger.debug("Firebase: error while getting stored user",e)}}async _signInWithProvider(e,t=this.socialLoginUXMode){return(t===o.POPUP?L:O)(this._auth,e).then(i=>(this._logger.info(`Firebase: signin with provider ${e.providerId} was successful`),i.user)).catch(async i=>i?.code===n.POPUP_BLOCKED&&(this._logger.warn(`Firebase: social signin popup blocked (${++this._popupErrors}`),this._popupFallsBackToRedirect&&this._popupErrors>1)?(this._popupErrors=0,this._signInWithProvider(e,o.REDIRECT)):(this._logger.error(`Firebase: sign in with ${e.providerId} errored`,i),await this._expandDifferentCredential(i),Promise.reject(i)))}_updateLocalUser(e){try{e?localStorage.setItem(this.storedUserKey,JSON.stringify(e)):localStorage.removeItem(this.storedUserKey),this._logger.debug("Firebase: updating local user",e),this._loggedUser=e}catch(t){this._logger.debug("Firebase: couldn't update local user",{user:e,error:t})}}_watchAuthState(){this._auth.onAuthStateChanged(e=>{this._logger.debug("Firebase: firebase detected auth state change",e),this._updateLocalUser(e||void 0)})}};export{n as SmpFirebaseErrors,l as SmpFirebaseService};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-DoiEsQxI.js';
|
|
2
2
|
import { SmpLoggerMethods } from '@tonysamperi/logger';
|
|
3
3
|
export { smpNoop } from '@tonysamperi/logger';
|
|
4
|
-
import { S as SmpResponseMessage, a as SmpGenericResponseBase } from './smp-generic-response-base.interface-
|
|
5
|
-
export {
|
|
6
|
-
export { S as SmpSocialSignInKeys, a as SmpSocialSignInUxModes } from './smp-
|
|
4
|
+
import { S as SmpResponseMessage, a as SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-C0On2LBc.js';
|
|
5
|
+
export { c as SmpResponseMessageBase } from './smp-generic-response-base.interface-C0On2LBc.js';
|
|
6
|
+
export { b as SmpFirebaseErrors, S as SmpSocialSignInKeys, a as SmpSocialSignInUxModes } from './smp-firebase-errors.enum-BlzgwNdc.js';
|
|
7
7
|
import { DateTime } from 'ts-luxon';
|
|
8
8
|
import 'rxjs';
|
|
9
9
|
|
|
10
|
+
type SmpDynamicFetchReturn<T, U> = T extends "blob" ? Blob : T extends "arraybuffer" ? ArrayBuffer : T extends "text" ? string : T extends "json" ? U : T;
|
|
11
|
+
|
|
10
12
|
declare abstract class SmpAbstractTtlCacheStrategy extends SmpAbstractCacheStrategy {
|
|
11
13
|
protected abstract _flushRaw(): void;
|
|
12
14
|
protected abstract _readRaw(key: string): unknown | undefined;
|
|
@@ -19,122 +21,6 @@ declare abstract class SmpAbstractTtlCacheStrategy extends SmpAbstractCacheStrat
|
|
|
19
21
|
protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
type SmpDynamicFetchReturn<T, U> = T extends "blob" ? Blob : T extends "arraybuffer" ? ArrayBuffer : T extends "text" ? string : T extends "json" ? U : T;
|
|
23
|
-
|
|
24
|
-
type SmpGenericConstructor<T = any, U = any> = new (...args: U[]) => T;
|
|
25
|
-
|
|
26
|
-
declare class SmpApiCommonUtils {
|
|
27
|
-
protected static _javascriptVariablePattern: string;
|
|
28
|
-
protected static _logger: SmpLoggerMethods;
|
|
29
|
-
protected static _pathParamRegex: RegExp;
|
|
30
|
-
static credentialsToBasicAuth(user: string, password: string): string;
|
|
31
|
-
static fromBearer(header?: string): string;
|
|
32
|
-
static getCountryFromReferer(referer: string): string | void;
|
|
33
|
-
static getLanguageFromReferer(referer: string): string | void;
|
|
34
|
-
static getLocaleFromReferer(referer: string): string | void;
|
|
35
|
-
static interpolateParams(urlTemplate: string, params: Record<string, string | number | boolean>): string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type ResponseMessageUnion = string | SmpResponseMessage;
|
|
39
|
-
interface SmpErrorResponseCreateOpts<T> {
|
|
40
|
-
messages: ResponseMessageUnion | ResponseMessageUnion[];
|
|
41
|
-
errorCode: number | string;
|
|
42
|
-
status: number;
|
|
43
|
-
data: T;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
declare class SmpGenericResponse<T, U = SmpGenericResponseBase> implements SmpGenericResponseBase<T> {
|
|
47
|
-
protected _messages: SmpResponseMessage[];
|
|
48
|
-
data?: T | undefined;
|
|
49
|
-
set messages(newValue: string | SmpResponseMessage | (SmpResponseMessage | string)[]);
|
|
50
|
-
get messages(): SmpResponseMessage[] | void;
|
|
51
|
-
constructor(_messages?: SmpResponseMessage[], data?: T | undefined);
|
|
52
|
-
static buildInfo<T = any>(msg: string | string[], data?: T): SmpGenericResponse<T>;
|
|
53
|
-
static buildSuccess<T = any>(msg: string | string[], data?: T): SmpGenericResponse<T>;
|
|
54
|
-
static fromPlain(plain: unknown): SmpGenericResponse<any, SmpGenericResponseBase<any>>;
|
|
55
|
-
isError(): boolean;
|
|
56
|
-
isSuccess(): boolean;
|
|
57
|
-
serialize(): U;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
declare class SmpErrorResponse<T = any> extends SmpGenericResponse<T, SmpGenericResponseBase & Pick<SmpErrorResponse, "errorCode" | "timestamp" | "status">> {
|
|
61
|
-
protected _errorCode: number | string;
|
|
62
|
-
protected _status: number;
|
|
63
|
-
static get DEFAULT_MESSAGES(): SmpResponseMessage[];
|
|
64
|
-
get errorCode(): number | string;
|
|
65
|
-
get status(): number;
|
|
66
|
-
get timestamp(): number;
|
|
67
|
-
protected _timestamp: number;
|
|
68
|
-
constructor(messages?: SmpResponseMessage[], _errorCode?: number | string, _status?: number, data?: T);
|
|
69
|
-
static create<T>({ messages, ...opts }?: Partial<SmpErrorResponseCreateOpts<T>>): SmpErrorResponse;
|
|
70
|
-
/**
|
|
71
|
-
* This shouldn't be necessary, but it's a workaround for this bug https://github.com/typestack/class-transformer/issues/1807
|
|
72
|
-
* @param plain
|
|
73
|
-
*/
|
|
74
|
-
static fromPlain(plain: unknown): SmpErrorResponse<any>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
declare const SMP_HEALTHZ: {
|
|
78
|
-
status: string;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
declare enum SmpRestVerbs {
|
|
82
|
-
GET = "GET",
|
|
83
|
-
POST = "POST",
|
|
84
|
-
PUT = "PUT",
|
|
85
|
-
DELETE = "DELETE",
|
|
86
|
-
PATCH = "PATCH"
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
interface SmpHttpConfig<T = any> {
|
|
90
|
-
cacheKey?: string;
|
|
91
|
-
clearCache?: boolean;
|
|
92
|
-
url: string;
|
|
93
|
-
method?: SmpRestVerbs | string;
|
|
94
|
-
useCredentials?: boolean;
|
|
95
|
-
body?: T;
|
|
96
|
-
headers?: Record<string, string>;
|
|
97
|
-
queryParams?: Record<string, string | number>;
|
|
98
|
-
transform?: boolean;
|
|
99
|
-
responseType?: "blob" | "arraybuffer" | "text" | "json" | "jsonp";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
interface ParseableErrorClass<T> {
|
|
103
|
-
fromPlain(plain: unknown): T;
|
|
104
|
-
}
|
|
105
|
-
declare class SmpHttpService {
|
|
106
|
-
protected static _cachePrefix: string;
|
|
107
|
-
protected static _cacheStrategy: SmpAbstractTtlCacheStrategy;
|
|
108
|
-
protected static _config: {
|
|
109
|
-
cachePrefix: string;
|
|
110
|
-
shared: Map<string, Promise<any>>;
|
|
111
|
-
};
|
|
112
|
-
protected static _errorClass: SmpGenericConstructor & ParseableErrorClass<any>;
|
|
113
|
-
protected static _mergeParamsFallbackBaseUrl: string;
|
|
114
|
-
static $http(config: SmpHttpConfig): Promise<SmpDynamicFetchReturn<SmpHttpConfig["responseType"], any>>;
|
|
115
|
-
static $http<T = any>(config: SmpHttpConfig): Promise<T>;
|
|
116
|
-
static $http(config: SmpHttpConfig): Promise<SmpDynamicFetchReturn<SmpHttpConfig["responseType"], Blob>>;
|
|
117
|
-
static $http(config: SmpHttpConfig): Promise<SmpDynamicFetchReturn<SmpHttpConfig["responseType"], ArrayBuffer>>;
|
|
118
|
-
static $http(config: SmpHttpConfig): Promise<SmpDynamicFetchReturn<SmpHttpConfig["responseType"], string>>;
|
|
119
|
-
static $http<T, U, V>(config: SmpHttpConfig): Promise<SmpDynamicFetchReturn<SmpHttpConfig["responseType"], U>>;
|
|
120
|
-
/**
|
|
121
|
-
* Internal method to generate ajax config
|
|
122
|
-
* @param config
|
|
123
|
-
* @protected
|
|
124
|
-
*/
|
|
125
|
-
static _generateAjax<T, U, V = unknown>(config: SmpHttpConfig<T>): Promise<SmpDynamicFetchReturn<typeof config.responseType, U>>;
|
|
126
|
-
static _generateAjaxBase<T, U, V = unknown>(config: SmpHttpConfig<T>): Promise<SmpDynamicFetchReturn<typeof config.responseType, U>>;
|
|
127
|
-
static cacheFlush(): void;
|
|
128
|
-
static mergeQueryParams(url: string, queryParams: SmpHttpConfig["queryParams"]): string;
|
|
129
|
-
protected static _cacheKey(key: string): string;
|
|
130
|
-
protected static _cachePop<T = any>(key: string): T | void;
|
|
131
|
-
protected static _cacheRead<T>(key: string): T | void;
|
|
132
|
-
protected static _cacheRemove(key: string): void;
|
|
133
|
-
protected static _cacheWrite<T>(key: string, value: T): void;
|
|
134
|
-
protected static _preprocessRequest<T>(config: SmpHttpConfig<T>): Promise<SmpHttpConfig<T>>;
|
|
135
|
-
protected static _preprocessResponse<T>(_config_: SmpHttpConfig<T>, res: Response): Promise<Response>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
24
|
declare class SmpBrowserCache extends SmpAbstractTtlCacheStrategy {
|
|
139
25
|
protected _storage: typeof localStorage | typeof sessionStorage;
|
|
140
26
|
protected _prefix: string;
|
|
@@ -218,6 +104,121 @@ declare enum SmpHttpStatusCodes {
|
|
|
218
104
|
NetworkAuthenticationRequired = 511
|
|
219
105
|
}
|
|
220
106
|
|
|
107
|
+
type SmpGenericConstructor<T = any, U = any> = new (...args: U[]) => T;
|
|
108
|
+
|
|
109
|
+
declare enum SmpRestVerbs {
|
|
110
|
+
GET = "GET",
|
|
111
|
+
POST = "POST",
|
|
112
|
+
PUT = "PUT",
|
|
113
|
+
DELETE = "DELETE",
|
|
114
|
+
PATCH = "PATCH"
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type SmpPrimitive = string | number | boolean | symbol;
|
|
118
|
+
|
|
119
|
+
interface SmpHttpTwoConfig<T = any> {
|
|
120
|
+
ttl?: number;
|
|
121
|
+
clearCache?: boolean;
|
|
122
|
+
url: string;
|
|
123
|
+
method?: SmpRestVerbs | string;
|
|
124
|
+
useCredentials?: boolean;
|
|
125
|
+
body?: T;
|
|
126
|
+
headers?: Record<string, string>;
|
|
127
|
+
queryParams?: Record<string, Exclude<SmpPrimitive, symbol> | Exclude<SmpPrimitive, symbol>[]>;
|
|
128
|
+
transform?: boolean;
|
|
129
|
+
responseType?: "blob" | "arraybuffer" | "text" | "json" | "jsonp";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface ParseableErrorClass<T> {
|
|
133
|
+
fromPlain(plain: unknown): T;
|
|
134
|
+
}
|
|
135
|
+
declare class SmpHttpTwoService {
|
|
136
|
+
protected static _cacheStrategy: SmpAbstractTtlCacheStrategy;
|
|
137
|
+
protected static _errorClass: SmpGenericConstructor & ParseableErrorClass<any>;
|
|
138
|
+
protected static _mergeParamsFallbackBaseUrl: string;
|
|
139
|
+
protected static _running: Map<string, Promise<any>>;
|
|
140
|
+
static $http(config: SmpHttpTwoConfig): Promise<SmpDynamicFetchReturn<SmpHttpTwoConfig["responseType"], any>>;
|
|
141
|
+
static $http<T = any>(config: SmpHttpTwoConfig): Promise<T>;
|
|
142
|
+
static $http(config: SmpHttpTwoConfig): Promise<SmpDynamicFetchReturn<SmpHttpTwoConfig["responseType"], Blob>>;
|
|
143
|
+
static $http(config: SmpHttpTwoConfig): Promise<SmpDynamicFetchReturn<SmpHttpTwoConfig["responseType"], ArrayBuffer>>;
|
|
144
|
+
static $http(config: SmpHttpTwoConfig): Promise<SmpDynamicFetchReturn<SmpHttpTwoConfig["responseType"], string>>;
|
|
145
|
+
static $http<T, U, V>(config: SmpHttpTwoConfig): Promise<SmpDynamicFetchReturn<SmpHttpTwoConfig["responseType"], U>>;
|
|
146
|
+
/**
|
|
147
|
+
* Internal method to generate ajax config
|
|
148
|
+
* @param config
|
|
149
|
+
* @protected
|
|
150
|
+
*/
|
|
151
|
+
static _generateAjax<T, U, V = unknown>(config: SmpHttpTwoConfig<T>): Promise<SmpDynamicFetchReturn<typeof config.responseType, U>>;
|
|
152
|
+
static _generateAjaxBase<T, U, V = unknown>(config: SmpHttpTwoConfig<T>): Promise<SmpDynamicFetchReturn<typeof config.responseType, U>>;
|
|
153
|
+
static cacheFlush(): void;
|
|
154
|
+
static mergeQueryParams(url: string, queryParams: SmpHttpTwoConfig["queryParams"]): string;
|
|
155
|
+
protected static _generateCacheKey(config: SmpHttpTwoConfig): string;
|
|
156
|
+
protected static _preprocessRequest<T>(config: SmpHttpTwoConfig<T>): Promise<SmpHttpTwoConfig<T>>;
|
|
157
|
+
protected static _preprocessResponse<T>(_config_: SmpHttpTwoConfig<T>, res: Response): Promise<Response>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare class SmpApiCommonUtils {
|
|
161
|
+
protected static _javascriptVariablePattern: string;
|
|
162
|
+
protected static _logger: SmpLoggerMethods;
|
|
163
|
+
protected static _pathParamRegex: RegExp;
|
|
164
|
+
static credentialsToBasicAuth(user: string, password: string): string;
|
|
165
|
+
static fromBearer(header?: string): string;
|
|
166
|
+
static getCountryFromReferer(referer: string): string | void;
|
|
167
|
+
static getLanguageFromReferer(referer: string): string | void;
|
|
168
|
+
static getLocaleFromReferer(referer: string): string | void;
|
|
169
|
+
static interpolateParams(urlTemplate: string, params: Record<string, string | number | boolean>): string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type ResponseMessageUnion = string | SmpResponseMessage;
|
|
173
|
+
interface SmpErrorResponseCreateOpts<T> {
|
|
174
|
+
messages: ResponseMessageUnion | ResponseMessageUnion[];
|
|
175
|
+
errorCode: number | string;
|
|
176
|
+
status: number;
|
|
177
|
+
data: T;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface SmpGenericResponseCreateOpts<T = any> {
|
|
181
|
+
messages: string | SmpResponseMessage | (string | SmpResponseMessage)[];
|
|
182
|
+
data: T;
|
|
183
|
+
type: SmpResponseMessageTypes;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
declare class SmpGenericResponse<T, U = SmpGenericResponseBase> implements SmpGenericResponseBase<T> {
|
|
187
|
+
protected _messages: SmpResponseMessage[];
|
|
188
|
+
data?: T | undefined;
|
|
189
|
+
set messages(newValue: string | SmpResponseMessage | (SmpResponseMessage | string)[]);
|
|
190
|
+
get messages(): SmpResponseMessage[] | void;
|
|
191
|
+
constructor(_messages?: SmpResponseMessage[], data?: T | undefined);
|
|
192
|
+
static create<T = any>(config: Partial<SmpGenericResponseCreateOpts<T>>): SmpGenericResponse<T>;
|
|
193
|
+
static fromPlain(plain: unknown): SmpGenericResponse<any, SmpGenericResponseBase<any>>;
|
|
194
|
+
isError(): boolean;
|
|
195
|
+
isSuccess(): boolean;
|
|
196
|
+
serialize(): U;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
declare class SmpErrorResponse<T = any> extends SmpGenericResponse<T, SmpGenericResponseBase & Pick<SmpErrorResponse, "errorCode" | "timestamp" | "status">> {
|
|
200
|
+
protected _errorCode: number | string;
|
|
201
|
+
protected _status: number;
|
|
202
|
+
static get DEFAULT_MESSAGES(): SmpResponseMessage[];
|
|
203
|
+
set errorCode(value: number | string);
|
|
204
|
+
get errorCode(): number | string;
|
|
205
|
+
get status(): number;
|
|
206
|
+
set timestamp(newValue: number);
|
|
207
|
+
get timestamp(): number;
|
|
208
|
+
protected _timestamp: number;
|
|
209
|
+
constructor(messages?: SmpResponseMessage[], _errorCode?: number | string, _status?: number, data?: T);
|
|
210
|
+
static create<T>({ messages, ...opts }?: Partial<SmpErrorResponseCreateOpts<T>>): SmpErrorResponse;
|
|
211
|
+
/**
|
|
212
|
+
* This shouldn't be necessary, but it's a workaround for this bug https://github.com/typestack/class-transformer/issues/1807
|
|
213
|
+
* @param plain
|
|
214
|
+
*/
|
|
215
|
+
static fromPlain(plain: unknown): SmpErrorResponse<any>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
declare const SMP_HEALTHZ: {
|
|
219
|
+
status: string;
|
|
220
|
+
};
|
|
221
|
+
|
|
221
222
|
declare class SmpBaseJwtTokenPlain {
|
|
222
223
|
access_token: string;
|
|
223
224
|
exp: number;
|
|
@@ -235,8 +236,6 @@ declare class SmpBaseJwtToken {
|
|
|
235
236
|
serialize(): SmpBaseJwtTokenPlain;
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
type SmpPrimitive = string | number | boolean | symbol;
|
|
239
|
-
|
|
240
239
|
declare class WordArray {
|
|
241
240
|
sigBytes: number;
|
|
242
241
|
words: number[];
|
|
@@ -734,19 +733,6 @@ declare class SmpSecureCode {
|
|
|
734
733
|
protected _encode(): string;
|
|
735
734
|
}
|
|
736
735
|
|
|
737
|
-
declare enum SmpFirebaseErrors {
|
|
738
|
-
DIFFERENT_CREDENTIAL = "auth/account-exists-with-different-credential",
|
|
739
|
-
DIFFERENT_CREDENTIAL_APPLE = "auth/account-exists-with-different-credential/apple",
|
|
740
|
-
DIFFERENT_CREDENTIAL_FACEBOOK = "auth/account-exists-with-different-credential/facebook",
|
|
741
|
-
DIFFERENT_CREDENTIAL_GOOGLE = "auth/account-exists-with-different-credential/google",
|
|
742
|
-
EMAIL_EXISTS = "auth/email-already-exists",
|
|
743
|
-
INVALID_ACTION_CODE = "auth/invalid-action-code",
|
|
744
|
-
POPUP_BLOCKED = "auth/popup-blocked",
|
|
745
|
-
POPUP_CLOSED_BY_USER = "auth/popup-closed-by-user",
|
|
746
|
-
USER_NOT_FOUND = "auth/user-not-found",
|
|
747
|
-
WRONG_PASSWORD = "auth/wrong-password"
|
|
748
|
-
}
|
|
749
|
-
|
|
750
736
|
declare enum SmpGiftcardTransactionOps {
|
|
751
737
|
ACTIVATE = "ACTIVATE",
|
|
752
738
|
BLOCK = "BLOCK",
|
|
@@ -785,14 +771,13 @@ declare enum SmpGiftcardTransactionHashStrategies {
|
|
|
785
771
|
|
|
786
772
|
/**
|
|
787
773
|
* Base implementation that you can extend, even customizing the static parts like #SmpGiftcardTransaction._AES_ENCODER.
|
|
788
|
-
* You can create your own instance of
|
|
774
|
+
* You can create your own instance of SmpAesCrypt to override it.
|
|
789
775
|
*/
|
|
790
776
|
declare class SmpGiftcardTransaction implements SmpGiftcardTransactionPlain {
|
|
791
777
|
readonly gc: string;
|
|
792
778
|
readonly op: SmpGiftcardTransactionOps;
|
|
793
779
|
readonly ot?: string | undefined;
|
|
794
780
|
protected static _AES_ENCODER: SmpAesCrypt;
|
|
795
|
-
protected static _LOGGER: SmpLoggerMethods;
|
|
796
781
|
protected static _OP_CODES: Record<SmpGiftcardTransactionOps, string>;
|
|
797
782
|
protected static readonly _SEP: string;
|
|
798
783
|
get dto(): DateTime;
|
|
@@ -921,7 +906,7 @@ declare class SmpCommonUtils {
|
|
|
921
906
|
* @param iteratee the map fn
|
|
922
907
|
*/
|
|
923
908
|
static mapObject<T = any>(objLike: any, iteratee: (v: any, indexOrKey: string | number, arr?: string[]) => any): T[];
|
|
924
|
-
static mapObjectKeys<T extends string = string>(obj: Record<T, any>, callback: (key: string, value: any) =>
|
|
909
|
+
static mapObjectKeys<T extends string = string>(obj: Record<T, any>, callback: (key: string, value: any) => string): Record<string, any>;
|
|
925
910
|
static mapObjectValues<T extends string = string>(obj: Partial<Record<T, any>>, callback: (value: any, key: string) => any): Record<string, any>;
|
|
926
911
|
static noop(): void;
|
|
927
912
|
static objectHasValue<T extends object>(obj: T, value: any): boolean;
|
|
@@ -983,6 +968,10 @@ declare class SmpRegularExpressions {
|
|
|
983
968
|
protected static _language: RegExp;
|
|
984
969
|
}
|
|
985
970
|
|
|
971
|
+
type SmpWithDateTimeAsDate<T, Keys extends keyof T = keyof T> = Omit<T, Keys> & {
|
|
972
|
+
[K in Keys]: T[K] extends DateTime | null | undefined ? Exclude<T[K], DateTime> | Date : T[K];
|
|
973
|
+
};
|
|
974
|
+
|
|
986
975
|
declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
|
|
987
976
|
private static _storage;
|
|
988
977
|
protected get _staticSelf(): typeof SmpInMemoryCache;
|
|
@@ -998,6 +987,6 @@ declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
|
|
|
998
987
|
*/
|
|
999
988
|
declare function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
|
|
1000
989
|
|
|
1001
|
-
declare const VERSION: "2.0.0-beta.
|
|
990
|
+
declare const VERSION: "2.0.0-beta.5";
|
|
1002
991
|
|
|
1003
|
-
export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpApiCommonUtils, SmpBaseJwtToken, SmpBaseJwtTokenPlain, SmpBrowserCache, SmpCachedValue, SmpCommonUtils, SmpCrypto, SmpErrorResponse, type SmpErrorResponseCreateOpts, SmpFilterException,
|
|
992
|
+
export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpApiCommonUtils, SmpBaseJwtToken, SmpBaseJwtTokenPlain, SmpBrowserCache, SmpCachedValue, SmpCommonUtils, SmpCrypto, type SmpDynamicFetchReturn, SmpErrorResponse, type SmpErrorResponseCreateOpts, SmpFilterException, type SmpGenericConstructor, SmpGenericResponse, SmpGenericResponseBase, type SmpGenericResponseCreateOpts, SmpGiftcardTransaction, type SmpGiftcardTransactionConfig, SmpGiftcardTransactionHashStrategies, SmpGiftcardTransactionOps, type SmpGiftcardTransactionPlain, SmpHttpSessionStorageCache, SmpHttpStatusCodes, type SmpHttpTwoConfig, SmpHttpTwoService, SmpInMemoryCache, type SmpMarketingCloudValidationResponse, type SmpMarketingCloudValidationResponseKo, type SmpMarketingCloudValidationResponseOk, SmpMarketingCloudValidators, type SmpPrimitive, SmpRegularExpressions, SmpResponseMessage, SmpResponseMessageTypes, SmpRestVerbs, SmpSecureCode, SmpSid, type SmpWithDateTimeAsDate, VERSION, smpApplyMixin, smpIsSmpCachedValue };
|