@tonysamperi/ts-mapi-core 2.0.0-beta.4 → 2.0.0-beta.6

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.
Files changed (30) hide show
  1. package/changelog.md +8 -1
  2. package/dist/cjs/firebase.cjs +1 -1
  3. package/dist/cjs/firebase.cjs.map +1 -1
  4. package/dist/cjs/firebase.d.cts +2 -1
  5. package/dist/cjs/index.cjs +1 -1
  6. package/dist/cjs/index.cjs.map +1 -1
  7. package/dist/cjs/index.d.cts +136 -144
  8. package/dist/cjs/rxjs.cjs +1 -1
  9. package/dist/cjs/rxjs.cjs.map +1 -1
  10. package/dist/cjs/rxjs.d.cts +4 -4
  11. package/dist/cjs/{smp-cached-value.interface-DoiEsQxI.d.cts → smp-cached-value.interface-BdPg-J7L.d.cts} +2 -2
  12. package/dist/cjs/smp-firebase-errors.enum-BlzgwNdc.d.cts +25 -0
  13. package/dist/cjs/{smp-generic-response-base.interface-D0jHrkjw.d.cts → smp-generic-response-base.interface-C0On2LBc.d.cts} +1 -1
  14. package/dist/cjs/zod.cjs +1 -1
  15. package/dist/cjs/zod.cjs.map +1 -1
  16. package/dist/cjs/zod.d.cts +9 -9
  17. package/dist/esm/firebase.d.ts +2 -1
  18. package/dist/esm/firebase.js +1 -1
  19. package/dist/esm/index.d.ts +136 -144
  20. package/dist/esm/index.js +1 -1
  21. package/dist/esm/rxjs.d.ts +4 -4
  22. package/dist/esm/rxjs.js +1 -1
  23. package/dist/esm/{smp-cached-value.interface-DoiEsQxI.d.ts → smp-cached-value.interface-BdPg-J7L.d.ts} +2 -2
  24. package/dist/esm/smp-firebase-errors.enum-BlzgwNdc.d.ts +25 -0
  25. package/dist/esm/{smp-generic-response-base.interface-D0jHrkjw.d.ts → smp-generic-response-base.interface-C0On2LBc.d.ts} +1 -1
  26. package/dist/esm/zod.d.ts +9 -9
  27. package/dist/esm/zod.js +1 -1
  28. package/package.json +9 -4
  29. package/dist/cjs/smp-social-sign-in-ux-modes.enum-Cw9H3EqT.d.cts +0 -12
  30. package/dist/esm/smp-social-sign-in-ux-modes.enum-Cw9H3EqT.d.ts +0 -12
@@ -1,140 +1,26 @@
1
- import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-DoiEsQxI.cjs';
1
+ import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-BdPg-J7L.cjs';
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-D0jHrkjw.cjs';
5
- export { b as SmpResponseMessageBase, c as SmpResponseMessageTypes } from './smp-generic-response-base.interface-D0jHrkjw.cjs';
6
- export { S as SmpSocialSignInKeys, a as SmpSocialSignInUxModes } from './smp-social-sign-in-ux-modes.enum-Cw9H3EqT.cjs';
4
+ import { S as SmpResponseMessage, a as SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-C0On2LBc.cjs';
5
+ export { c as SmpResponseMessageBase } from './smp-generic-response-base.interface-C0On2LBc.cjs';
6
+ export { b as SmpFirebaseErrors, S as SmpSocialSignInKeys, a as SmpSocialSignInUxModes } from './smp-firebase-errors.enum-BlzgwNdc.cjs';
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;
13
15
  protected abstract _removeRaw(key: string): void;
14
16
  protected abstract _writeRaw(key: string, value: unknown, ttl?: number): void;
15
17
  flush(): void;
16
- read<T = any>(key: string): T | undefined;
18
+ read<T = unknown>(key: string): T | undefined;
17
19
  remove(key: string): void;
18
- write<T = any>(key: string, value: T, ttl?: number): void;
20
+ write<T = unknown>(key: string, value: T, ttl?: number): void;
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[];
@@ -683,7 +682,8 @@ declare class SmpAesCrypt {
683
682
  protected _password: string;
684
683
  protected _salt: string;
685
684
  protected _initVector?: string | undefined;
686
- protected get _iv(): WordArray | undefined;
685
+ protected _iv: WordArray | undefined;
686
+ protected _key: WordArray;
687
687
  protected _mode: typeof CBC;
688
688
  protected _padding: typeof PKCS7;
689
689
  constructor(_password: string, _salt: string, _initVector?: string | undefined);
@@ -709,6 +709,7 @@ declare class SmpAesCrypt {
709
709
  declare class SmpCrypto {
710
710
  static base64Decode(str: string): string;
711
711
  static base64Encode(str: string): string;
712
+ static generateCorrelationId(): string;
712
713
  static md5(data: string): string;
713
714
  static sha1(data: string): string;
714
715
  static sha256(data: string): string;
@@ -734,19 +735,6 @@ declare class SmpSecureCode {
734
735
  protected _encode(): string;
735
736
  }
736
737
 
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
738
  declare enum SmpGiftcardTransactionOps {
751
739
  ACTIVATE = "ACTIVATE",
752
740
  BLOCK = "BLOCK",
@@ -785,14 +773,13 @@ declare enum SmpGiftcardTransactionHashStrategies {
785
773
 
786
774
  /**
787
775
  * Base implementation that you can extend, even customizing the static parts like #SmpGiftcardTransaction._AES_ENCODER.
788
- * You can create your own instance of KikAesCrypt to override it.
776
+ * You can create your own instance of SmpAesCrypt to override it.
789
777
  */
790
778
  declare class SmpGiftcardTransaction implements SmpGiftcardTransactionPlain {
791
779
  readonly gc: string;
792
780
  readonly op: SmpGiftcardTransactionOps;
793
781
  readonly ot?: string | undefined;
794
782
  protected static _AES_ENCODER: SmpAesCrypt;
795
- protected static _LOGGER: SmpLoggerMethods;
796
783
  protected static _OP_CODES: Record<SmpGiftcardTransactionOps, string>;
797
784
  protected static readonly _SEP: string;
798
785
  get dto(): DateTime;
@@ -808,7 +795,7 @@ declare class SmpGiftcardTransaction implements SmpGiftcardTransactionPlain {
808
795
  protected _hashStrategy: (str: string) => WordArray;
809
796
  /**
810
797
  *
811
- * @param gc giftcard code
798
+ * @param gc gift card code
812
799
  * @param op operation
813
800
  * @param ot original transaction in case of refund
814
801
  * @param unixTimestampOrMilliseconds
@@ -866,6 +853,7 @@ declare class SmpCommonUtils {
866
853
  static assertIsTruthy<T>(condition: T, withMessage?: string): asserts condition;
867
854
  static buildPath(...args: any[]): string;
868
855
  static downloadBlob(blob: Blob, filename: string): void;
856
+ static fixDecimalPrecision(value: number, precision?: number): number;
869
857
  static generateRandomHexString(length?: number): string;
870
858
  static generateUUID(): string;
871
859
  static getDecimalPrecision(val: number | string): number;
@@ -921,7 +909,7 @@ declare class SmpCommonUtils {
921
909
  * @param iteratee the map fn
922
910
  */
923
911
  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) => any): Record<string, any>;
912
+ static mapObjectKeys<T extends string = string>(obj: Record<T, any>, callback: (key: string, value: any) => string): Record<string, any>;
925
913
  static mapObjectValues<T extends string = string>(obj: Partial<Record<T, any>>, callback: (value: any, key: string) => any): Record<string, any>;
926
914
  static noop(): void;
927
915
  static objectHasValue<T extends object>(obj: T, value: any): boolean;
@@ -983,6 +971,10 @@ declare class SmpRegularExpressions {
983
971
  protected static _language: RegExp;
984
972
  }
985
973
 
974
+ type SmpWithDateTimeAsDate<T, Keys extends keyof T = keyof T> = Omit<T, Keys> & {
975
+ [K in Keys]: T[K] extends DateTime | null | undefined ? Exclude<T[K], DateTime> | Date : T[K];
976
+ };
977
+
986
978
  declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
987
979
  private static _storage;
988
980
  protected get _staticSelf(): typeof SmpInMemoryCache;
@@ -998,6 +990,6 @@ declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
998
990
  */
999
991
  declare function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
1000
992
 
1001
- declare const VERSION: "2.0.0-beta.4";
993
+ declare const VERSION: "2.0.0-beta.6";
1002
994
 
1003
- export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpApiCommonUtils, SmpBaseJwtToken, SmpBaseJwtTokenPlain, SmpBrowserCache, SmpCachedValue, SmpCommonUtils, SmpCrypto, SmpErrorResponse, type SmpErrorResponseCreateOpts, SmpFilterException, SmpFirebaseErrors, type SmpGenericConstructor, SmpGenericResponse, SmpGenericResponseBase, SmpGiftcardTransaction, type SmpGiftcardTransactionConfig, SmpGiftcardTransactionHashStrategies, SmpGiftcardTransactionOps, type SmpGiftcardTransactionPlain, type SmpHttpConfig, SmpHttpService, SmpHttpSessionStorageCache, SmpHttpStatusCodes, SmpInMemoryCache, type SmpMarketingCloudValidationResponse, type SmpMarketingCloudValidationResponseKo, type SmpMarketingCloudValidationResponseOk, SmpMarketingCloudValidators, type SmpPrimitive, SmpRegularExpressions, SmpResponseMessage, SmpRestVerbs, SmpSecureCode, SmpSid, VERSION, smpApplyMixin, smpIsSmpCachedValue };
995
+ 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 };
package/dist/cjs/rxjs.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var s=(t,r)=>f(t,"name",{value:r,configurable:!0});var C=(t,r)=>{for(var e in r)f(t,e,{get:r[e],enumerable:!0})},N=(t,r,e,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of j(r))!E.call(t,n)&&n!==e&&f(t,n,{get:()=>r[n],enumerable:!(o=b(r,n))||o.enumerable});return t};var O=t=>N(f({},"__esModule",{value:!0}),t);var D={};C(D,{SmpAbstractRxjsTtlCacheStrategy:()=>a,SmpRxjsInMemoryCache:()=>x,smpRxjsCatchOnly:()=>I,smpRxjsQueue:()=>T,smpRxjsSequence:()=>V,smpRxjsThrowIfEmpty:()=>y,smpRxjsThrowOnCondition:()=>M});module.exports=O(D);var d=require("rxjs"),_=require("ts-luxon");var u=class{static{s(this,"SmpAbstractCacheStrategy")}};function R(t){return typeof t=="object"&&t!==null&&"value"in t&&"expiry"in t&&typeof t.expiry=="number"}s(R,"smpIsSmpCachedValue");var a=class extends u{static{s(this,"SmpAbstractRxjsTtlCacheStrategy")}flush(){return this._flushRaw()}read(r){return this._readRaw(r).pipe((0,d.map)(e=>{if(this._isSmpCachedValue(e)){if(e.expiry>=_.DateTime.now().ts)return e.value;this._removeRaw(r).subscribe();return}return e}))}remove(r){return this._removeRaw(r)}write(r,e,o){let n;if(isNaN(+o)||+o<=0)n=this._writeRaw(r,e,o);else{let l=_.DateTime.now().ts+o*1e3,w={value:e,expiry:l};n=this._writeRaw(r,w,o)}return n.subscribe(),n}_isSmpCachedValue(r){return R(r)}};var m=require("rxjs");function I(t,r){return e=>e.pipe((0,m.catchError)(o=>(typeof t==typeof isNaN?v(t)?A(o,t):t(o):!1)?r(o):(0,m.throwError)(()=>o)))}s(I,"smpRxjsCatchOnly");function v(t){try{return Reflect.construct(String,[],t),!0}catch{return!1}}s(v,"isConstructor");function A(t,r){return typeof t=="object"&&t!==null&&t.constructor===r}s(A,"isExactInstance");var c=require("rxjs");var x=class extends a{static{s(this,"SmpRxjsInMemoryCache")}static _storage=new Map;get _staticSelf(){return this.constructor}_flushRaw(){return this._staticSelf._storage.clear(),(0,c.of)(void 0)}_readRaw(r){return(0,c.of)(this._staticSelf._storage.get(r))}_removeRaw(r){return this._staticSelf._storage.delete(r),(0,c.of)(void 0)}_writeRaw(r,e){return this._staticSelf._storage.set(r,e),(0,c.of)(void 0)}};var i=require("rxjs");function S(t){let r=[];function e(o){return o>=t.length?(0,i.of)(r):(0,i.defer)(()=>t[o]()).pipe((0,i.switchMap)(n=>(r[o]=n,e(o+1))))}return s(e,"runStep"),e(0)}s(S,"smpRxjsSequence");function T(t){if(Array.isArray(t))return S(t);{let r=Object.keys(t),e=r.map(o=>t[o]);return S(e).pipe((0,i.map)(o=>{let n={};return r.forEach((l,w)=>{n[l]=o[w]}),n}))}}s(T,"smpRxjsQueue");var p=require("rxjs");function V(t){return(0,p.from)(t).pipe((0,p.concatMap)(e=>e()),(0,p.toArray)())}s(V,"smpRxjsSequence");var g=require("rxjs");function y(t=J){return r=>r.pipe((0,g.map)(e=>{if(~q.indexOf(JSON.stringify(e)))throw t(e);return e}))}s(y,"smpRxjsThrowIfEmpty");var q=[void 0,null,!1,0,"","0",[],{}].map(t=>JSON.stringify(t)),J=s(()=>new Error,"defaultErrorFactory");var h=require("rxjs");function M(t,r){return e=>e.pipe((0,h.filter)(o=>!t(o)),(0,h.defaultIfEmpty)(!1),y(r))}s(M,"smpRxjsThrowOnCondition");0&&(module.exports={SmpAbstractRxjsTtlCacheStrategy,SmpRxjsInMemoryCache,smpRxjsCatchOnly,smpRxjsQueue,smpRxjsSequence,smpRxjsThrowIfEmpty,smpRxjsThrowOnCondition});
1
+ "use strict";var a=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var s=(r,t)=>a(r,"name",{value:t,configurable:!0});var N=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},A=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of I(t))!T.call(r,n)&&n!==e&&a(r,n,{get:()=>t[n],enumerable:!(o=O(t,n))||o.enumerable});return r};var v=r=>A(a({},"__esModule",{value:!0}),r);var Q={};N(Q,{SmpAbstractRxjsTtlCacheStrategy:()=>c,SmpRxjsInMemoryCache:()=>x,smpRxjsCatchOnly:()=>S,smpRxjsQueue:()=>g,smpRxjsSequence:()=>b,smpRxjsThrowIfEmpty:()=>l,smpRxjsThrowOnCondition:()=>E});module.exports=v(Q);var d=require("rxjs"),R=require("ts-luxon");var u=class{static{s(this,"SmpAbstractCacheStrategy")}};function _(r){return typeof r=="object"&&r!==null&&"value"in r&&"expiry"in r&&typeof r.expiry=="number"}s(_,"smpIsSmpCachedValue");var c=class extends u{static{s(this,"SmpAbstractRxjsTtlCacheStrategy")}flush(){return this._flushRaw()}read(t){return this._readRaw(t).pipe((0,d.map)(e=>{if(this._isSmpCachedValue(e)){if(e.expiry>=R.DateTime.now().ts)return e.value;this._removeRaw(t).subscribe();return}return e}))}remove(t){return this._removeRaw(t)}write(t,e,o){let n;if(isNaN(+o)||+o<=0)n=this._writeRaw(t,e,o);else{let m=R.DateTime.now().ts+o*1e3,y={value:e,expiry:m};n=this._writeRaw(t,y,o)}return n.subscribe({error:s(m=>console.error(`${this.constructor.name}::write: error occurred`,m),"error")}),n}_isSmpCachedValue(t){return _(t)}};var h=require("rxjs");function S(r,t){return e=>e.pipe((0,h.catchError)(o=>(typeof r==typeof isNaN?q(r)?M(o,r):r(o):!1)?t(o):(0,h.throwError)(()=>o)))}s(S,"smpRxjsCatchOnly");function q(r){try{return Reflect.construct(String,[],r),!0}catch{return!1}}s(q,"isConstructor");function M(r,t){return typeof r=="object"&&r!==null&&r.constructor===t}s(M,"isExactInstance");var i=require("rxjs");var x=class extends c{static{s(this,"SmpRxjsInMemoryCache")}static _storage=new Map;get _staticSelf(){return this.constructor}_flushRaw(){return(0,i.defer)(()=>(this._staticSelf._storage.clear(),(0,i.of)(void 0)))}_readRaw(t){return(0,i.defer)(()=>(0,i.of)(this._staticSelf._storage.get(t)))}_removeRaw(t){return(0,i.defer)(()=>(this._staticSelf._storage.delete(t),(0,i.of)(void 0)))}_writeRaw(t,e){return this._staticSelf._storage.set(t,e),(0,i.of)(void 0)}};var p=require("rxjs");function j(r){let t=[];function e(o){return o>=r.length?(0,p.of)(t):(0,p.defer)(()=>r[o]()).pipe((0,p.switchMap)(n=>(t[o]=n,e(o+1))))}return s(e,"runStep"),e(0)}s(j,"smpRxjsSequence");function g(r){if(Array.isArray(r))return j(r);{let t=Object.keys(r),e=t.map(o=>r[o]);return j(e).pipe((0,p.map)(o=>{let n={};return t.forEach((m,y)=>{n[m]=o[y]}),n}))}}s(g,"smpRxjsQueue");var f=require("rxjs");function b(r){return(0,f.from)(r).pipe((0,f.concatMap)(e=>e()),(0,f.toArray)())}s(b,"smpRxjsSequence");var C=require("rxjs");function l(r=J){return t=>t.pipe((0,C.map)(e=>{if(~V.indexOf(JSON.stringify(e)))throw r(e);return e}))}s(l,"smpRxjsThrowIfEmpty");var V=[void 0,null,!1,0,"","0",[],{}].map(r=>JSON.stringify(r)),J=s(()=>new Error,"defaultErrorFactory");var w=require("rxjs");function E(r,t){return e=>e.pipe((0,w.filter)(o=>!r(o)),(0,w.defaultIfEmpty)(!1),l(t))}s(E,"smpRxjsThrowOnCondition");0&&(module.exports={SmpAbstractRxjsTtlCacheStrategy,SmpRxjsInMemoryCache,smpRxjsCatchOnly,smpRxjsQueue,smpRxjsSequence,smpRxjsThrowIfEmpty,smpRxjsThrowOnCondition});
2
2
  //# sourceMappingURL=rxjs.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/rxjs.ts","../../src/shared/rxjs/smp-abstract-rxjs-ttl-cache-strategy.class.ts","../../src/shared/utils/cache/smp-abstract-cache-strategy.class.ts","../../src/shared/utils/cache/smp-is-smp-cached-value.function.ts","../../src/shared/rxjs/smp-rxjs-catch-only.function.ts","../../src/shared/rxjs/smp-rxjs-in-memory-cache.class.ts","../../src/shared/rxjs/smp-rxjs-queue.function.ts","../../src/shared/rxjs/smp-rxjs-sequence.function.ts","../../src/shared/rxjs/smp-rxjs-throw-if-empty.function.ts","../../src/shared/rxjs/smp-rxjs-throw-on-condition.function.ts"],"sourcesContent":["export * from \"./shared/rxjs/index.js\";\n","import {map, Observable} from \"rxjs\";\nimport {DateTime} from \"ts-luxon\";\n//\nimport {SmpAbstractCacheStrategy} from \"../utils/cache/smp-abstract-cache-strategy.class.js\";\nimport {SmpCachedValue} from \"../utils/cache/smp-cached-value.interface.js\";\nimport {smpIsSmpCachedValue} from \"../utils/cache/smp-is-smp-cached-value.function.js\";\n\nexport abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheStrategy {\n\n protected abstract _flushRaw(): Observable<void>;\n\n protected abstract _readRaw(key: string): Observable<unknown | undefined>;\n\n protected abstract _removeRaw(key: string): Observable<void>;\n\n protected abstract _writeRaw(key: string, value: unknown, ttl?: number): Observable<void>;\n\n flush(): Observable<void> {\n return this._flushRaw();\n }\n\n read<T = any>(key: string): Observable<T | undefined> {\n return this._readRaw(key).pipe(\n map((storedValue) => {\n if (this._isSmpCachedValue<T>(storedValue)) {\n if (storedValue.expiry >= DateTime.now().ts) {\n return storedValue.value as T;\n }\n this._removeRaw(key).subscribe(); // fire-and-forget\n\n return void 0;\n }\n\n return storedValue as T | undefined;\n })\n );\n }\n\n remove(key: string) {\n return this._removeRaw(key);\n }\n\n write<T = any>(key: string, value: T, ttl?: number): Observable<void> {\n let obs$: Observable<void>;\n\n if (isNaN(+ttl!) || +ttl! <= 0) {\n obs$ = this._writeRaw(key, value, ttl);\n }\n else {\n const expiry = DateTime.now().ts + ttl! * 1000;\n const wrappedValue: SmpCachedValue<T> = {\n value,\n expiry\n };\n obs$ = this._writeRaw(key, wrappedValue, ttl);\n }\n\n // Fire-and-forget\n obs$.subscribe();\n\n return obs$;\n }\n\n protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return smpIsSmpCachedValue(value);\n }\n}\n","import {Observable} from \"rxjs\";\n\n/**\n * Abstract class representing a caching strategy. This class is intended to be extended by concrete implementations\n * and provides an interface for performing common caching operations such as reading, writing, removing, and flushing cache entries.\n * You shouldn't need to implement this: you can go with SmpAbstractTtlCacheStrategy or SmpRxjsAbstractCacheStrategy, depending on what type of cache you want to implement.\n * For instance, for a local cache, you may stay sync, while for a Valkey cache, you should start with the rxjs.\n */\nexport abstract class SmpAbstractCacheStrategy {\n abstract read<T = any>(key: string): T | undefined | Observable<T | undefined>;\n\n abstract write<T = any>(key: string, value: T, ttl?: number): void | Observable<void>;\n\n abstract remove(key: string): void | Observable<void>;\n\n abstract flush(): void | Observable<void>;\n}\n","import {SmpCachedValue} from \"./smp-cached-value.interface.js\";\n\n/**\n * Tells you if a value is a SmpCachedValue\n * @param value\n */\nexport function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"value\" in value &&\n \"expiry\" in value &&\n typeof (value as any).expiry === \"number\"\n );\n}\n","import {Observable, OperatorFunction, catchError, throwError} from \"rxjs\";\nimport type {ObservableInput, ObservedValueOf} from \"rxjs\";\n\nexport function smpRxjsCatchOnly<T, E extends Error, O extends ObservableInput<any>>(\n errorFilter: (new (...args: any[]) => E) | ((err: unknown) => boolean),\n selector: (err: E) => O\n): OperatorFunction<T, T | ObservedValueOf<O>> {\n return (source: Observable<T>) =>\n source.pipe(\n catchError((err: unknown) => {\n const matches = typeof errorFilter === typeof isNaN\n ? isConstructor(errorFilter)\n ? isExactInstance(err, errorFilter as new (...args: any[]) => E)\n : (errorFilter as (err: unknown) => boolean)(err)\n : false;\n\n if (matches) {\n return selector(err as E);\n }\n return throwError(() => err);\n })\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nfunction isConstructor(fn: unknown): fn is Function {\n try {\n // try creating a dummy instance\n Reflect.construct(String, [], fn as any);\n return true;\n }\n catch {\n return false;\n }\n}\n\n// Ensures that the error is an *exact* instance of the given error constructor, not a subclass\nfunction isExactInstance<E extends Error>(err: unknown, ctor: new (...args: any[]) => E): boolean {\n return (\n typeof err === \"object\" &&\n err !== null &&\n err.constructor === ctor\n );\n}\n","import {defer, Observable, of} from \"rxjs\";\n//\nimport {SmpAbstractRxjsTtlCacheStrategy} from \"./smp-abstract-rxjs-ttl-cache-strategy.class.js\";\n\nexport class SmpRxjsInMemoryCache extends SmpAbstractRxjsTtlCacheStrategy {\n\n private static _storage = new Map<string, any>();\n\n protected get _staticSelf(): typeof SmpRxjsInMemoryCache {\n return this.constructor as typeof SmpRxjsInMemoryCache;\n }\n\n protected _flushRaw(): Observable<void> {\n this._staticSelf._storage.clear();\n\n return of(void 0);\n }\n\n protected _readRaw(key: string): Observable<any | undefined> {\n return of(this._staticSelf._storage.get(key));\n }\n\n protected _removeRaw(key: string): Observable<void> {\n this._staticSelf._storage.delete(key);\n\n return of(void 0);\n }\n\n protected _writeRaw(key: string, value: any): Observable<void> {\n this._staticSelf._storage.set(key, value);\n\n return of(void 0);\n }\n}\n\n","import {map, Observable, of, defer, switchMap} from \"rxjs\";\n\nfunction smpRxjsSequence<T extends any[]>(steps: { [K in keyof T]: () => Observable<T[K]> }): Observable<T> {\n const results: Partial<T>[] = [];\n\n function runStep(index: number): Observable<T> {\n if (index >= steps.length) {\n return of(results as T);\n }\n\n return defer(() => steps[index]()).pipe(\n switchMap((value) => {\n results[index] = value;\n return runStep(index + 1);\n })\n );\n }\n\n return runStep(0);\n}\n\n// Overloads for array or object input\ntype ObsFnMap = Record<string, () => Observable<any>>;\n\nexport function smpRxjsQueue<T extends any[]>(source: { [K in keyof T]: () => Observable<T[K]> }): Observable<T>;\nexport function smpRxjsQueue<T extends ObsFnMap>(source: T): Observable<{ [K in keyof T]: T[K] extends () => Observable<infer U> ? U : never }>;\nexport function smpRxjsQueue(\n source: (() => Observable<any>)[] | ObsFnMap\n): Observable<any> {\n if (Array.isArray(source)) {\n // use a strongly typed sequence for the array of steps\n return smpRxjsSequence(source as any);\n }\n else {\n // for object, convert values, then reconstruct object mapping with correct types\n const keys = Object.keys(source);\n const stepsArray = keys.map((key) => source[key]);\n\n return smpRxjsSequence(stepsArray as any).pipe(\n map((results: any[]) => {\n const acc: any = {};\n keys.forEach((key, i) => {\n acc[key] = results[i];\n });\n return acc;\n })\n );\n }\n}\n\n\n","import {concatMap, from, Observable, toArray} from \"rxjs\";\n\n/**\n * Old version of the sequence. Now rewritten using recursion, which is way faster.\n * But you can use this if you want to stick with the rxjs pattern\n * @param steps\n */\nexport function smpRxjsSequence<T extends any[]>(\n steps: { [K in keyof T]: () => Observable<T[K]> }\n): Observable<T> {\n // Cast to readonly tuple of functions to keep tuple inference\n const stepFunctions = steps as readonly (() => Observable<T[number]>)[];\n\n return from(stepFunctions).pipe(\n concatMap(step => step()),\n toArray()\n // TS loses tuple typing here, so we cast the result back to T\n // This cast is safe because we control the input and ordering\n ) as Observable<T>;\n}\n","import {map, Observable, OperatorFunction} from \"rxjs\";\n\n/**\n * If the source observable completes emitting an empty value (empty array or object will be considered empty), it will emit\n * an error. The error will be created at that time by the optional\n * `errorFactory` argument, otherwise, the error will be {@link Error}.\n *\n * ## Example\n *\n * Throw an error if the query didn't match anything\n *\n * ```ts\n * import { of, takeUntil, timer, throwIfEmpty } from 'rxjs';\n *\n * const query$ = of([]);\n *\n * query$.pipe(\n * smpRxjsThrowIfEmpty(() => new Error('The query had no results'))\n * )\n * .subscribe({\n * next() {\n * console.log(\"The query had results\");\n * },\n * error(err) {\n * console.error(err.message);\n * }\n * });\n * ```\n *\n * @param errorFactory A factory function called to produce the\n * error to be thrown when the source observable completes without emitting a\n * value.\n * @return A function that returns an Observable that throws an error if the\n * source Observable completed without emitting.\n */\nexport function smpRxjsThrowIfEmpty<T>(errorFactory: (value: T) => any = defaultErrorFactory): OperatorFunction<T, T> {\n return (source: Observable<T>) => source.pipe(\n map(v => {\n if (~emptyValues.indexOf(JSON.stringify(v))) {\n throw errorFactory(v);\n }\n\n return v;\n })\n );\n}\n\nconst emptyValues = [void 0, null, false, 0, \"\", \"0\", [], {}].map((v) =>\n JSON.stringify(v)\n);\n\nconst defaultErrorFactory = (): Error => new Error();\n","import {defaultIfEmpty, filter, Observable, OperatorFunction} from \"rxjs\";\n//\nimport {smpRxjsThrowIfEmpty} from \"./smp-rxjs-throw-if-empty.function.js\";\n\n/**\n * Custom RxJS operator that filters the source observable based on a condition\n * and throws an error if the resulting observable is empty.\n *\n * @template T The type of items emitted by the source observable.\n * @param {function(T): boolean} condition - A function that takes a value from the source observable and returns a boolean.\n * If the function returns `true`, the value will be emitted; otherwise, it will be filtered out.\n * @param {function(): Error} [errorFactory] - An optional function that returns an error to be thrown if the resulting observable is empty.\n * If not provided, a default error will be thrown.\n * @returns {OperatorFunction<T, T>} An operator function that can be used in the RxJS pipeline.\n *\n * @example\n * import { of } from 'rxjs';\n * import { smpRxjsThrowOnCondition } from \"./path-to-your-file\";\n *\n * const source$ = of(1, 5, -3, 7, 12).pipe(\n * smpRxjsThrowOnCondition(value => value >= 0, () => new Error(\"Value is less than 0\")),\n * smpRxjsThrowOnCondition(value => value > 12, () => new Error(\"Value is lower than 12\"))\n * );\n *\n * source$.subscribe({\n * next: value => console.log(\"Value:\", value),\n * error: err => console.error(\"Error:\", err)\n * });\n */\nexport function smpRxjsThrowOnCondition<T>(\n condition: (value: T) => boolean,\n errorFactory?: () => any\n): OperatorFunction<T, T> {\n return (source: Observable<T>) =>\n source.pipe(\n filter((v: T) => !condition(v)), // Invert the condition because if I need to throw on that condition we should filter all that don't match\n defaultIfEmpty(false as unknown as T), // We nuke type errors, cause when falsy smpRxjsThrowIfEmpty will throw\n smpRxjsThrowIfEmpty(errorFactory)\n );\n}\n"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AO,EAAG,GAAI,IAAK,CAAA,EAAI,CAAC,GAAGF,IAAKC,GAC/DG,KAAKC,UAAUJ,CAAAA,CAAAA,EAGbJ,EAAsBS,EAAA,IAAa,IAAIC,MAAjB,uBCnD5B,IAAAC,EAAmE,gBA6B5D,SAASC,EACZC,EACAC,EAAwB,CAExB,OAAQC,GACJA,EAAOC,QACHC,UAAQC,GAAS,CAACL,EAAUK,CAAAA,CAAAA,KAC5BC,kBAAe,EAAA,EACfC,EAAoBN,CAAAA,CAAAA,CAEhC,CAVgBF,EAAAA,EAAAA","names":["rxjs_exports","__export","SmpAbstractRxjsTtlCacheStrategy","SmpRxjsInMemoryCache","smpRxjsCatchOnly","smpRxjsQueue","smpRxjsSequence","smpRxjsThrowIfEmpty","smpRxjsThrowOnCondition","__toCommonJS","import_rxjs","import_ts_luxon","SmpAbstractCacheStrategy","smpIsSmpCachedValue","value","expiry","SmpAbstractRxjsTtlCacheStrategy","SmpAbstractCacheStrategy","flush","_flushRaw","read","key","_readRaw","pipe","map","storedValue","_isSmpCachedValue","expiry","DateTime","now","ts","value","_removeRaw","subscribe","remove","write","ttl","obs$","isNaN","_writeRaw","wrappedValue","smpIsSmpCachedValue","import_rxjs","smpRxjsCatchOnly","errorFilter","selector","source","pipe","catchError","err","isNaN","isConstructor","isExactInstance","throwError","fn","Reflect","construct","String","ctor","import_rxjs","SmpRxjsInMemoryCache","SmpAbstractRxjsTtlCacheStrategy","_storage","Map","_staticSelf","_flushRaw","clear","of","_readRaw","key","get","_removeRaw","delete","_writeRaw","value","set","import_rxjs","smpRxjsSequence","steps","results","runStep","index","length","of","defer","pipe","switchMap","value","smpRxjsQueue","source","Array","isArray","keys","Object","stepsArray","map","key","acc","forEach","i","import_rxjs","smpRxjsSequence","steps","from","stepFunctions","pipe","concatMap","step","toArray","import_rxjs","smpRxjsThrowIfEmpty","errorFactory","defaultErrorFactory","source","pipe","map","v","emptyValues","indexOf","JSON","stringify","__name","Error","import_rxjs","smpRxjsThrowOnCondition","condition","errorFactory","source","pipe","filter","v","defaultIfEmpty","smpRxjsThrowIfEmpty"]}
1
+ {"version":3,"sources":["../../src/rxjs.ts","../../src/shared/rxjs/smp-abstract-rxjs-ttl-cache-strategy.class.ts","../../src/shared/utils/cache/smp-abstract-cache-strategy.class.ts","../../src/shared/utils/cache/smp-is-smp-cached-value.function.ts","../../src/shared/rxjs/smp-rxjs-catch-only.function.ts","../../src/shared/rxjs/smp-rxjs-in-memory-cache.class.ts","../../src/shared/rxjs/smp-rxjs-queue.function.ts","../../src/shared/rxjs/smp-rxjs-sequence.function.ts","../../src/shared/rxjs/smp-rxjs-throw-if-empty.function.ts","../../src/shared/rxjs/smp-rxjs-throw-on-condition.function.ts"],"sourcesContent":["export * from \"./shared/rxjs/index.js\";\n","import {map, Observable} from \"rxjs\";\nimport {DateTime} from \"ts-luxon\";\n//\nimport {SmpAbstractCacheStrategy} from \"../utils/cache/smp-abstract-cache-strategy.class.js\";\nimport {SmpCachedValue} from \"../utils/cache/smp-cached-value.interface.js\";\nimport {smpIsSmpCachedValue} from \"../utils/cache/smp-is-smp-cached-value.function.js\";\n\nexport abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheStrategy {\n\n protected abstract _flushRaw(): Observable<void>;\n\n protected abstract _readRaw(key: string): Observable<unknown | undefined>;\n\n protected abstract _removeRaw(key: string): Observable<void>;\n\n protected abstract _writeRaw(key: string, value: unknown, ttl?: number): Observable<void>;\n\n flush(): Observable<void> {\n return this._flushRaw();\n }\n\n read<T = unknown>(key: string): Observable<T | undefined> {\n return this._readRaw(key).pipe(\n map((storedValue) => {\n if (this._isSmpCachedValue<T>(storedValue)) {\n if (storedValue.expiry >= DateTime.now().ts) {\n return storedValue.value as T;\n }\n this._removeRaw(key).subscribe(); // fire-and-forget\n\n return void 0;\n }\n\n return storedValue as T | undefined;\n })\n );\n }\n\n remove(key: string) {\n return this._removeRaw(key);\n }\n\n write<T = any>(key: string, value: T, ttl?: number): Observable<void> {\n let obs$: Observable<void>;\n\n if (isNaN(+ttl!) || +ttl! <= 0) {\n obs$ = this._writeRaw(key, value, ttl);\n }\n else {\n const expiry = DateTime.now().ts + ttl! * 1000;\n const wrappedValue: SmpCachedValue<T> = {\n value,\n expiry\n };\n obs$ = this._writeRaw(key, wrappedValue, ttl);\n }\n\n // Fire-and-forget\n obs$.subscribe({\n error: (err) => console.error(`${this.constructor.name}::write: error occurred`, err)\n });\n\n return obs$;\n }\n\n protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return smpIsSmpCachedValue(value);\n }\n}\n","import {Observable} from \"rxjs\";\n\n/**\n * Abstract class representing a caching strategy. This class is intended to be extended by concrete implementations\n * and provides an interface for performing common caching operations such as reading, writing, removing, and flushing cache entries.\n * You shouldn't need to implement this: you can go with SmpAbstractTtlCacheStrategy or SmpRxjsAbstractCacheStrategy, depending on what type of cache you want to implement.\n * For instance, for a local cache, you may stay sync, while for a Valkey cache, you should start with the rxjs.\n */\nexport abstract class SmpAbstractCacheStrategy {\n abstract read<T = unknown>(key: string): T | undefined | Observable<T | undefined>;\n\n abstract write<T = unknown>(key: string, value: T, ttl?: number): void | Observable<void>;\n\n abstract remove(key: string): void | Observable<void>;\n\n abstract flush(): void | Observable<void>;\n}\n","import {SmpCachedValue} from \"./smp-cached-value.interface.js\";\n\n/**\n * Tells you if a value is a SmpCachedValue\n * @param value\n */\nexport function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"value\" in value &&\n \"expiry\" in value &&\n typeof (value as any).expiry === \"number\"\n );\n}\n","import {Observable, OperatorFunction, catchError, throwError} from \"rxjs\";\nimport type {ObservableInput, ObservedValueOf} from \"rxjs\";\n\nexport function smpRxjsCatchOnly<T, E extends Error, O extends ObservableInput<any>>(\n errorFilter: (new (...args: any[]) => E) | ((err: unknown) => boolean),\n selector: (err: E) => O\n): OperatorFunction<T, T | ObservedValueOf<O>> {\n return (source: Observable<T>) =>\n source.pipe(\n catchError((err: unknown) => {\n const matches = typeof errorFilter === typeof isNaN\n ? isConstructor(errorFilter)\n ? isExactInstance(err, errorFilter as new (...args: any[]) => E)\n : (errorFilter as (err: unknown) => boolean)(err)\n : false;\n\n if (matches) {\n return selector(err as E);\n }\n return throwError(() => err);\n })\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nfunction isConstructor(fn: unknown): fn is Function {\n try {\n // try creating a dummy instance\n Reflect.construct(String, [], fn as any);\n return true;\n }\n catch {\n return false;\n }\n}\n\n// Ensures that the error is an *exact* instance of the given error constructor, not a subclass\nfunction isExactInstance<E extends Error>(err: unknown, ctor: new (...args: any[]) => E): boolean {\n return (\n typeof err === \"object\" &&\n err !== null &&\n err.constructor === ctor\n );\n}\n","import {defer, Observable, of} from \"rxjs\";\n//\nimport {SmpAbstractRxjsTtlCacheStrategy} from \"./smp-abstract-rxjs-ttl-cache-strategy.class.js\";\n\nexport class SmpRxjsInMemoryCache extends SmpAbstractRxjsTtlCacheStrategy {\n\n private static _storage = new Map<string, unknown>();\n\n protected get _staticSelf(): typeof SmpRxjsInMemoryCache {\n return this.constructor as typeof SmpRxjsInMemoryCache;\n }\n\n protected _flushRaw(): Observable<void> {\n return defer(() => {\n this._staticSelf._storage.clear();\n\n return of(void 0);\n });\n }\n\n protected _readRaw(key: string): Observable<unknown | undefined> {\n return defer(() => {\n\n return of(this._staticSelf._storage.get(key));\n });\n }\n\n protected _removeRaw(key: string): Observable<void> {\n return defer(() => {\n this._staticSelf._storage.delete(key);\n\n return of(void 0);\n });\n }\n\n protected _writeRaw(key: string, value: any): Observable<void> {\n this._staticSelf._storage.set(key, value);\n\n return of(void 0);\n }\n}\n\n","import {map, Observable, of, defer, switchMap} from \"rxjs\";\n\nfunction smpRxjsSequence<T extends any[]>(steps: { [K in keyof T]: () => Observable<T[K]> }): Observable<T> {\n const results: Partial<T>[] = [];\n\n function runStep(index: number): Observable<T> {\n if (index >= steps.length) {\n return of(results as T);\n }\n\n return defer(() => steps[index]()).pipe(\n switchMap((value) => {\n results[index] = value;\n return runStep(index + 1);\n })\n );\n }\n\n return runStep(0);\n}\n\n// Overloads for array or object input\ntype ObsFnMap = Record<string, () => Observable<any>>;\n\nexport function smpRxjsQueue<T extends any[]>(source: { [K in keyof T]: () => Observable<T[K]> }): Observable<T>;\nexport function smpRxjsQueue<T extends ObsFnMap>(source: T): Observable<{ [K in keyof T]: T[K] extends () => Observable<infer U> ? U : never }>;\nexport function smpRxjsQueue(\n source: (() => Observable<any>)[] | ObsFnMap\n): Observable<any> {\n if (Array.isArray(source)) {\n // use a strongly typed sequence for the array of steps\n return smpRxjsSequence(source as any);\n }\n else {\n // for object, convert values, then reconstruct object mapping with correct types\n const keys = Object.keys(source);\n const stepsArray = keys.map((key) => source[key]);\n\n return smpRxjsSequence(stepsArray as any).pipe(\n map((results: any[]) => {\n const acc: any = {};\n keys.forEach((key, i) => {\n acc[key] = results[i];\n });\n return acc;\n })\n );\n }\n}\n\n\n","import {concatMap, from, Observable, toArray} from \"rxjs\";\n\n/**\n * Old version of the sequence. Now rewritten using recursion, which is way faster.\n * But you can use this if you want to stick with the rxjs pattern\n * @param steps\n */\nexport function smpRxjsSequence<T extends any[]>(\n steps: { [K in keyof T]: () => Observable<T[K]> }\n): Observable<T> {\n // Cast to readonly tuple of functions to keep tuple inference\n const stepFunctions = steps as readonly (() => Observable<T[number]>)[];\n\n return from(stepFunctions).pipe(\n concatMap(step => step()),\n toArray()\n // TS loses tuple typing here, so we cast the result back to T\n // This cast is safe because we control the input and ordering\n ) as Observable<T>;\n}\n","import {map, Observable, OperatorFunction} from \"rxjs\";\n\n/**\n * If the source observable completes emitting an empty value (empty array or object will be considered empty), it will emit\n * an error. The error will be created at that time by the optional\n * `errorFactory` argument, otherwise, the error will be {@link Error}.\n *\n * ## Example\n *\n * Throw an error if the query didn't match anything\n *\n * ```ts\n * import { of, takeUntil, timer, throwIfEmpty } from 'rxjs';\n *\n * const query$ = of([]);\n *\n * query$.pipe(\n * smpRxjsThrowIfEmpty(() => new Error('The query had no results'))\n * )\n * .subscribe({\n * next() {\n * console.log(\"The query had results\");\n * },\n * error(err) {\n * console.error(err.message);\n * }\n * });\n * ```\n *\n * @param errorFactory A factory function called to produce the\n * error to be thrown when the source observable completes without emitting a\n * value.\n * @return A function that returns an Observable that throws an error if the\n * source Observable completed without emitting.\n */\nexport function smpRxjsThrowIfEmpty<T>(errorFactory: (value: T) => any = defaultErrorFactory): OperatorFunction<T, T> {\n return (source: Observable<T>) => source.pipe(\n map(v => {\n if (~emptyValues.indexOf(JSON.stringify(v))) {\n throw errorFactory(v);\n }\n\n return v;\n })\n );\n}\n\nconst emptyValues = [void 0, null, false, 0, \"\", \"0\", [], {}].map((v) =>\n JSON.stringify(v)\n);\n\nconst defaultErrorFactory = (): Error => new Error();\n","import {defaultIfEmpty, filter, Observable, OperatorFunction} from \"rxjs\";\n//\nimport {smpRxjsThrowIfEmpty} from \"./smp-rxjs-throw-if-empty.function.js\";\n\n/**\n * Custom RxJS operator that filters the source observable based on a condition\n * and throws an error if the resulting observable is empty.\n *\n * @template T The type of items emitted by the source observable.\n * @param {function(T): boolean} condition - A function that takes a value from the source observable and returns a boolean.\n * If the function returns `true`, the value will be emitted; otherwise, it will be filtered out.\n * @param {function(): Error} [errorFactory] - An optional function that returns an error to be thrown if the resulting observable is empty.\n * If not provided, a default error will be thrown.\n * @returns {OperatorFunction<T, T>} An operator function that can be used in the RxJS pipeline.\n *\n * @example\n * import { of } from 'rxjs';\n * import { smpRxjsThrowOnCondition } from \"./path-to-your-file\";\n *\n * const source$ = of(1, 5, -3, 7, 12).pipe(\n * smpRxjsThrowOnCondition(value => value >= 0, () => new Error(\"Value is less than 0\")),\n * smpRxjsThrowOnCondition(value => value > 12, () => new Error(\"Value is lower than 12\"))\n * );\n *\n * source$.subscribe({\n * next: value => console.log(\"Value:\", value),\n * error: err => console.error(\"Error:\", err)\n * });\n */\nexport function smpRxjsThrowOnCondition<T>(\n condition: (value: T) => boolean,\n errorFactory?: (value: T) => any\n): OperatorFunction<T, T> {\n return (source: Observable<T>) =>\n source.pipe(\n filter((v: T) => !condition(v)), // Invert the condition because if I need to throw on that condition we should filter all that don't match\n defaultIfEmpty(false as unknown as T), // We nuke type errors, cause when falsy smpRxjsThrowIfEmpty will throw\n smpRxjsThrowIfEmpty(errorFactory)\n );\n}\n"],"mappings":"4dAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,EAAA,yBAAAC,EAAA,qBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,EAAA,wBAAAC,EAAA,4BAAAC,IAAA,eAAAC,EAAAT,GCAA,IAAAU,EAA8B,gBAC9BC,EAAuB,oBCOhB,IAAeC,EAAf,KAAeA,CANtB,MAMsBA,CAAAA,EAAAA,iCAQtB,ECVO,SAASC,EAAuBC,EAAc,CACjD,OACI,OAAOA,GAAU,UACjBA,IAAU,MACV,UAAWA,GACX,WAAYA,GACZ,OAAQA,EAAcC,QAAW,QAEzC,CARgBF,EAAAA,EAAAA,uBFCT,IAAeG,EAAf,cAAuDC,CAAAA,CAP9D,MAO8DA,CAAAA,EAAAA,wCAU1DC,OAA0B,CACtB,OAAO,KAAKC,UAAS,CACzB,CAEAC,KAAkBC,EAAwC,CACtD,OAAO,KAAKC,SAASD,CAAAA,EAAKE,QACtBC,OAAKC,GAAAA,CACD,GAAI,KAAKC,kBAAqBD,CAAAA,EAAc,CACxC,GAAIA,EAAYE,QAAUC,WAASC,IAAG,EAAGC,GACrC,OAAOL,EAAYM,MAEvB,KAAKC,WAAWX,CAAAA,EAAKY,UAAS,EAE9B,MACJ,CAEA,OAAOR,CACX,CAAA,CAAA,CAER,CAEAS,OAAOb,EAAa,CAChB,OAAO,KAAKW,WAAWX,CAAAA,CAC3B,CAEAc,MAAed,EAAaU,EAAUK,EAAgC,CAClE,IAAIC,EAEJ,GAAIC,MAAM,CAACF,CAAAA,GAAS,CAACA,GAAQ,EACzBC,EAAO,KAAK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OC,QAFeD,CAEVE,EAAeC,QACvBC,aAAUC,GAAQA,EAAAA,CAAAA,KAClBC,WAAAA,CAAAA,CAIR,CAZgBP,EAAAA,EAAAA,mBCPhB,IAAAQ,EAAgD,gBAmCzC,SAASC,EAAuBC,EAAkCC,EAAmB,CACxF,OAAQC,GAA0BA,EAAOC,QACrCC,OAAIC,GAAAA,CACA,GAAI,CAACC,EAAYC,QAAQC,KAAKC,UAAUJ,CAAAA,CAAAA,EACpC,MAAML,EAAaK,CAAAA,EAGvB,OAAOA,CACX,CAAA,CAAA,CAER,CAVgBN,EAAAA,EAAAA,uBAYhB,IAAMO,EAAc,CAAC,OAAQ,KAAM,GAAO,EAAG,GAAI,IAAK,CAAA,EAAI,CAAC,GAAGF,IAAKC,GAC/DG,KAAKC,UAAUJ,CAAAA,CAAAA,EAGbJ,EAAsBS,EAAA,IAAa,IAAIC,MAAjB,uBCnD5B,IAAAC,EAAmE,gBA6B5D,SAASC,EACZC,EACAC,EAAgC,CAEhC,OAAQC,GACJA,EAAOC,QACHC,UAAQC,GAAS,CAACL,EAAUK,CAAAA,CAAAA,KAC5BC,kBAAe,EAAA,EACfC,EAAoBN,CAAAA,CAAAA,CAEhC,CAVgBF,EAAAA,EAAAA","names":["rxjs_exports","__export","SmpAbstractRxjsTtlCacheStrategy","SmpRxjsInMemoryCache","smpRxjsCatchOnly","smpRxjsQueue","smpRxjsSequence","smpRxjsThrowIfEmpty","smpRxjsThrowOnCondition","__toCommonJS","import_rxjs","import_ts_luxon","SmpAbstractCacheStrategy","smpIsSmpCachedValue","value","expiry","SmpAbstractRxjsTtlCacheStrategy","SmpAbstractCacheStrategy","flush","_flushRaw","read","key","_readRaw","pipe","map","storedValue","_isSmpCachedValue","expiry","DateTime","now","ts","value","_removeRaw","subscribe","remove","write","ttl","obs$","isNaN","_writeRaw","wrappedValue","error","__name","err","console","name","smpIsSmpCachedValue","import_rxjs","smpRxjsCatchOnly","errorFilter","selector","source","pipe","catchError","err","isNaN","isConstructor","isExactInstance","throwError","fn","Reflect","construct","String","ctor","import_rxjs","SmpRxjsInMemoryCache","SmpAbstractRxjsTtlCacheStrategy","_storage","Map","_staticSelf","_flushRaw","defer","clear","of","_readRaw","key","get","_removeRaw","delete","_writeRaw","value","set","import_rxjs","smpRxjsSequence","steps","results","runStep","index","length","of","defer","pipe","switchMap","value","smpRxjsQueue","source","Array","isArray","keys","Object","stepsArray","map","key","acc","forEach","i","import_rxjs","smpRxjsSequence","steps","from","stepFunctions","pipe","concatMap","step","toArray","import_rxjs","smpRxjsThrowIfEmpty","errorFactory","defaultErrorFactory","source","pipe","map","v","emptyValues","indexOf","JSON","stringify","__name","Error","import_rxjs","smpRxjsThrowOnCondition","condition","errorFactory","source","pipe","filter","v","defaultIfEmpty","smpRxjsThrowIfEmpty"]}
@@ -1,5 +1,5 @@
1
1
  import { Observable, ObservableInput, OperatorFunction, ObservedValueOf } from 'rxjs';
2
- import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-DoiEsQxI.cjs';
2
+ import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-BdPg-J7L.cjs';
3
3
 
4
4
  declare abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheStrategy {
5
5
  protected abstract _flushRaw(): Observable<void>;
@@ -7,7 +7,7 @@ declare abstract class SmpAbstractRxjsTtlCacheStrategy extends SmpAbstractCacheS
7
7
  protected abstract _removeRaw(key: string): Observable<void>;
8
8
  protected abstract _writeRaw(key: string, value: unknown, ttl?: number): Observable<void>;
9
9
  flush(): Observable<void>;
10
- read<T = any>(key: string): Observable<T | undefined>;
10
+ read<T = unknown>(key: string): Observable<T | undefined>;
11
11
  remove(key: string): Observable<void>;
12
12
  write<T = any>(key: string, value: T, ttl?: number): Observable<void>;
13
13
  protected _isSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
@@ -19,7 +19,7 @@ declare class SmpRxjsInMemoryCache extends SmpAbstractRxjsTtlCacheStrategy {
19
19
  private static _storage;
20
20
  protected get _staticSelf(): typeof SmpRxjsInMemoryCache;
21
21
  protected _flushRaw(): Observable<void>;
22
- protected _readRaw(key: string): Observable<any | undefined>;
22
+ protected _readRaw(key: string): Observable<unknown | undefined>;
23
23
  protected _removeRaw(key: string): Observable<void>;
24
24
  protected _writeRaw(key: string, value: any): Observable<void>;
25
25
  }
@@ -101,6 +101,6 @@ declare function smpRxjsThrowIfEmpty<T>(errorFactory?: (value: T) => any): Opera
101
101
  * error: err => console.error("Error:", err)
102
102
  * });
103
103
  */
104
- declare function smpRxjsThrowOnCondition<T>(condition: (value: T) => boolean, errorFactory?: () => any): OperatorFunction<T, T>;
104
+ declare function smpRxjsThrowOnCondition<T>(condition: (value: T) => boolean, errorFactory?: (value: T) => any): OperatorFunction<T, T>;
105
105
 
106
106
  export { SmpAbstractRxjsTtlCacheStrategy, SmpRxjsInMemoryCache, smpRxjsCatchOnly, smpRxjsQueue, smpRxjsSequence, smpRxjsThrowIfEmpty, smpRxjsThrowOnCondition };
@@ -7,8 +7,8 @@ import { Observable } from 'rxjs';
7
7
  * For instance, for a local cache, you may stay sync, while for a Valkey cache, you should start with the rxjs.
8
8
  */
9
9
  declare abstract class SmpAbstractCacheStrategy {
10
- abstract read<T = any>(key: string): T | undefined | Observable<T | undefined>;
11
- abstract write<T = any>(key: string, value: T, ttl?: number): void | Observable<void>;
10
+ abstract read<T = unknown>(key: string): T | undefined | Observable<T | undefined>;
11
+ abstract write<T = unknown>(key: string, value: T, ttl?: number): void | Observable<void>;
12
12
  abstract remove(key: string): void | Observable<void>;
13
13
  abstract flush(): void | Observable<void>;
14
14
  }
@@ -0,0 +1,25 @@
1
+ declare enum SmpSocialSignInKeys {
2
+ APPLE = "APPLE",
3
+ FACEBOOK = "FACEBOOK",
4
+ GOOGLE = "GOOGLE"
5
+ }
6
+
7
+ declare enum SmpSocialSignInUxModes {
8
+ POPUP = "POPUP",
9
+ REDIRECT = "REDIRECT"
10
+ }
11
+
12
+ declare enum SmpFirebaseErrors {
13
+ DIFFERENT_CREDENTIAL = "auth/account-exists-with-different-credential",
14
+ DIFFERENT_CREDENTIAL_APPLE = "auth/account-exists-with-different-credential/apple",
15
+ DIFFERENT_CREDENTIAL_FACEBOOK = "auth/account-exists-with-different-credential/facebook",
16
+ DIFFERENT_CREDENTIAL_GOOGLE = "auth/account-exists-with-different-credential/google",
17
+ EMAIL_EXISTS = "auth/email-already-exists",
18
+ INVALID_ACTION_CODE = "auth/invalid-action-code",
19
+ POPUP_BLOCKED = "auth/popup-blocked",
20
+ POPUP_CLOSED_BY_USER = "auth/popup-closed-by-user",
21
+ USER_NOT_FOUND = "auth/user-not-found",
22
+ WRONG_PASSWORD = "auth/wrong-password"
23
+ }
24
+
25
+ export { SmpSocialSignInKeys as S, SmpSocialSignInUxModes as a, SmpFirebaseErrors as b };
@@ -24,4 +24,4 @@ interface SmpGenericResponseBase<T = any> {
24
24
  messages: SmpResponseMessageBase[] | void;
25
25
  }
26
26
 
27
- export { SmpResponseMessage as S, type SmpGenericResponseBase as a, type SmpResponseMessageBase as b, SmpResponseMessageTypes as c };
27
+ export { SmpResponseMessage as S, SmpResponseMessageTypes as a, type SmpGenericResponseBase as b, type SmpResponseMessageBase as c };
package/dist/cjs/zod.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var D=Object.create;var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var a=(t,e)=>u(t,"name",{value:e,configurable:!0});var C=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},l=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of b(e))!w.call(t,d)&&d!==n&&u(t,d,{get:()=>e[d],enumerable:!(i=g(e,d))||i.enumerable});return t};var S=(t,e,n)=>(n=t!=null?D(_(t)):{},l(e||!t||!t.__esModule?u(n,"default",{value:t,enumerable:!0}):n,t)),T=t=>l(u({},"__esModule",{value:!0}),t);var R={};C(R,{SmpZodDateTime:()=>x,smpGenericResponseSchema:()=>N,smpResponseMessageSchema:()=>h,smpZodDateTime:()=>O});module.exports=T(R);var f=require("zod");var I=(function(t){return t.INFO="INFO",t.SUCCESS="SUCCESS",t.WARNING="WARNING",t.ERROR="ERROR",t})({});var h=f.z.object({message:f.z.string(),type:f.z.nativeEnum(I)});var p=require("zod");var N=p.z.object({data:p.z.unknown().optional(),messages:p.z.array(h).optional()});var s=S(require("zod"),1),m=require("ts-luxon");var x=class t extends s.default.ZodType{static{a(this,"SmpZodDateTime")}constructor(e){super({typeName:"SmpZodDateTime",coerce:e?.coerce??!1,checks:e?.checks??[]})}_parse(e){let n=this._getOrReturnCtx(e),i=n.data;if(this._def.coerce&&(i=this._coerceToDateTime(i),!(i instanceof m.DateTime)||!i.isValid))return s.default.addIssueToContext(n,{code:s.ZodIssueCode.invalid_type,expected:s.ZodParsedType.date,received:s.ZodParsedType.unknown,path:n.path,message:"Invalid date format"}),s.default.INVALID;if((!(i instanceof m.DateTime)||!i.isValid)&&!this._def.coerce)return s.default.addIssueToContext(n,{code:s.ZodIssueCode.invalid_type,expected:s.ZodParsedType.date,received:s.ZodParsedType.unknown,path:n.path,message:"Input must be a valid DateTime object"}),s.default.INVALID;let d={min:a((o,r,c)=>{if(o.min&&r<o.min)return{code:s.ZodIssueCode.too_small,minimum:o.min.toMillis(),type:"date",inclusive:!0,message:o.message??`Date must be \u2265 ${o.min.toISODate()}`,path:c.path}},"min"),max:a((o,r,c)=>{if(o.max&&r>o.max)return{code:s.ZodIssueCode.too_big,maximum:o.max.toMillis(),type:"date",inclusive:!0,message:o.message??`Date must be \u2264 ${o.max.toISODate()}`,path:c.path}},"max"),between:a((o,r,c)=>{if(o.min&&o.max&&(r<o.min||r>o.max))return{code:s.ZodIssueCode.custom,message:o.message??`Date must be between ${o.min.toISODate()} and ${o.max.toISODate()}`,path:c.path}},"between")};for(let o of this._def.checks)if(i instanceof m.DateTime&&i.isValid){let r=d[o.kind](o,i,n);r&&s.default.addIssueToContext(n,r)}return n.common.issues.length>0?s.default.INVALID:s.default.OK(i)}between(e,n,i){return new t({...this._def,checks:[...this._def.checks,{kind:"between",min:e.toUTC(),max:n.toUTC(),message:i}]})}coerce(){return new t({...this._def,coerce:!0})}max(e,n){return new t({...this._def,checks:[...this._def.checks,{kind:"max",max:e.toUTC(),message:n}]})}min(e,n){return new t({...this._def,checks:[...this._def.checks,{kind:"min",min:e.toUTC(),message:n}]})}_coerceToDateTime(e){if(e instanceof m.DateTime&&e.isValid)return e;let n={string:a(()=>m.DateTime.fromJSDate(new Date(e)),"string"),number:a(()=>m.DateTime.fromMillis(e),"number"),object:a(()=>m.DateTime.fromJSDate(e),"object"),default:a(()=>null,"default")};return(n[typeof e]||n.default)()}},O=a((t={})=>new x({coerce:t.coerce??!1,checks:[]}),"smpZodDateTime");0&&(module.exports={SmpZodDateTime,smpGenericResponseSchema,smpResponseMessageSchema,smpZodDateTime});
1
+ "use strict";var D=Object.create;var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var a=(t,e)=>u(t,"name",{value:e,configurable:!0});var C=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},l=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of b(e))!w.call(t,d)&&d!==n&&u(t,d,{get:()=>e[d],enumerable:!(i=g(e,d))||i.enumerable});return t};var S=(t,e,n)=>(n=t!=null?D(_(t)):{},l(e||!t||!t.__esModule?u(n,"default",{value:t,enumerable:!0}):n,t)),T=t=>l(u({},"__esModule",{value:!0}),t);var R={};C(R,{SmpZodDateTime:()=>x,smpGenericResponseSchema:()=>N,smpResponseMessageSchema:()=>h,smpZodDateTime:()=>O});module.exports=T(R);var p=require("zod");var f=require("zod");var I=(function(t){return t.INFO="INFO",t.SUCCESS="SUCCESS",t.WARNING="WARNING",t.ERROR="ERROR",t})({});var h=f.z.object({message:f.z.string(),type:f.z.nativeEnum(I)});var N=p.z.object({data:p.z.unknown().optional(),messages:p.z.array(h).optional()});var s=S(require("zod"),1),m=require("ts-luxon");var x=class t extends s.default.ZodType{static{a(this,"SmpZodDateTime")}constructor(e){super({typeName:"SmpZodDateTime",coerce:e?.coerce??!1,checks:e?.checks??[]})}_parse(e){let n=this._getOrReturnCtx(e),i=n.data;if(this._def.coerce&&(i=this._coerceToDateTime(i),!(i instanceof m.DateTime)||!i.isValid))return s.default.addIssueToContext(n,{code:s.ZodIssueCode.invalid_type,expected:s.ZodParsedType.date,received:s.ZodParsedType.unknown,path:n.path,message:"Invalid date format"}),s.default.INVALID;if((!(i instanceof m.DateTime)||!i.isValid)&&!this._def.coerce)return s.default.addIssueToContext(n,{code:s.ZodIssueCode.invalid_type,expected:s.ZodParsedType.date,received:s.ZodParsedType.unknown,path:n.path,message:"Input must be a valid DateTime object"}),s.default.INVALID;let d={min:a((o,r,c)=>{if(o.min&&r<o.min)return{code:s.ZodIssueCode.too_small,minimum:o.min.toMillis(),type:"date",inclusive:!0,message:o.message??`Date must be \u2265 ${o.min.toISODate()}`,path:c.path}},"min"),max:a((o,r,c)=>{if(o.max&&r>o.max)return{code:s.ZodIssueCode.too_big,maximum:o.max.toMillis(),type:"date",inclusive:!0,message:o.message??`Date must be \u2264 ${o.max.toISODate()}`,path:c.path}},"max"),between:a((o,r,c)=>{if(o.min&&o.max&&(r<o.min||r>o.max))return{code:s.ZodIssueCode.custom,message:o.message??`Date must be between ${o.min.toISODate()} and ${o.max.toISODate()}`,path:c.path}},"between")};for(let o of this._def.checks)if(i instanceof m.DateTime&&i.isValid){let r=d[o.kind](o,i,n);r&&s.default.addIssueToContext(n,r)}return n.common.issues.length>0?s.default.INVALID:s.default.OK(i)}between(e,n,i){return new t({...this._def,checks:[...this._def.checks,{kind:"between",min:e.toUTC(),max:n.toUTC(),message:i}]})}coerce(){return new t({...this._def,coerce:!0})}max(e,n){return new t({...this._def,checks:[...this._def.checks,{kind:"max",max:e.toUTC(),message:n}]})}min(e,n){return new t({...this._def,checks:[...this._def.checks,{kind:"min",min:e.toUTC(),message:n}]})}_coerceToDateTime(e){if(e instanceof m.DateTime&&e.isValid)return e;let n={string:a(()=>m.DateTime.fromJSDate(new Date(e)),"string"),number:a(()=>m.DateTime.fromMillis(e),"number"),object:a(()=>m.DateTime.fromJSDate(e),"object"),default:a(()=>null,"default")};return(n[typeof e]||n.default)()}},O=a((t={})=>new x({coerce:t.coerce??!1,checks:[]}),"smpZodDateTime");0&&(module.exports={SmpZodDateTime,smpGenericResponseSchema,smpResponseMessageSchema,smpZodDateTime});
2
2
  //# sourceMappingURL=zod.cjs.map