@tonysamperi/ts-mapi-core 2.0.0 → 2.1.0
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/README.md +32 -0
- package/changelog.md +22 -0
- package/dist/cjs/eslint.cjs +2 -0
- package/dist/cjs/eslint.cjs.map +1 -0
- package/dist/cjs/eslint.d.cts +107 -0
- package/dist/cjs/firebase.cjs +1 -1
- package/dist/cjs/firebase.cjs.map +1 -1
- package/dist/cjs/firebase.d.cts +20 -6
- package/dist/cjs/index.cjs +2 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +19 -6
- package/dist/cjs/{smp-generic-response-base.interface-C0On2LBc.d.cts → smp-generic-response-base.interface-BSdPo_xm.d.cts} +2 -0
- package/dist/cjs/zod.cjs +1 -1
- package/dist/cjs/zod.cjs.map +1 -1
- package/dist/cjs/zod.d.cts +2 -1
- package/dist/esm/chunk-7X4DHW36.js +1 -0
- package/dist/esm/{chunk-VBEMFJKM.js → chunk-OVNQKUGW.js} +1 -1
- package/dist/esm/dynamo.js +1 -1
- package/dist/esm/eslint.d.ts +107 -0
- package/dist/esm/eslint.js +1 -0
- package/dist/esm/firebase.d.ts +20 -6
- package/dist/esm/firebase.js +1 -1
- package/dist/esm/index.d.ts +19 -6
- package/dist/esm/index.js +2 -1
- package/dist/esm/rxjs.js +1 -1
- package/dist/esm/{smp-generic-response-base.interface-C0On2LBc.d.ts → smp-generic-response-base.interface-BSdPo_xm.d.ts} +2 -0
- package/dist/esm/zod.d.ts +2 -1
- package/dist/esm/zod.js +1 -1
- package/package.json +25 -9
- package/dist/esm/chunk-EI7MMDWY.js +0 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
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 SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-
|
|
5
|
-
export { c as SmpResponseMessageBase } from './smp-generic-response-base.interface-
|
|
4
|
+
import { S as SmpResponseMessage, a as SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-BSdPo_xm.cjs';
|
|
5
|
+
export { c as SmpResponseMessageBase } from './smp-generic-response-base.interface-BSdPo_xm.cjs';
|
|
6
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';
|
|
@@ -111,6 +111,8 @@ declare enum SmpRestVerbs {
|
|
|
111
111
|
POST = "POST",
|
|
112
112
|
PUT = "PUT",
|
|
113
113
|
DELETE = "DELETE",
|
|
114
|
+
HEAD = "HEAD",
|
|
115
|
+
OPTIONS = "OPTIONS",
|
|
114
116
|
PATCH = "PATCH"
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -127,6 +129,8 @@ interface SmpHttpTwoConfig<T = any> {
|
|
|
127
129
|
queryParams?: Record<string, Exclude<SmpPrimitive, symbol> | Exclude<SmpPrimitive, symbol>[]>;
|
|
128
130
|
transform?: boolean;
|
|
129
131
|
responseType?: "blob" | "arraybuffer" | "text" | "json" | "jsonp";
|
|
132
|
+
/** Timeout in milliseconds after which the request will be aborted */
|
|
133
|
+
timeout?: number;
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
interface ParseableErrorClass<T> {
|
|
@@ -191,6 +195,7 @@ declare class SmpGenericResponse<T, U = SmpGenericResponseBase> implements SmpGe
|
|
|
191
195
|
constructor(_messages?: SmpResponseMessage[], data?: T | undefined);
|
|
192
196
|
static create<T = any>(config: Partial<SmpGenericResponseCreateOpts<T>>): SmpGenericResponse<T>;
|
|
193
197
|
static fromPlain(plain: unknown): SmpGenericResponse<any, SmpGenericResponseBase<any>>;
|
|
198
|
+
clone(): this;
|
|
194
199
|
isError(): boolean;
|
|
195
200
|
isSuccess(): boolean;
|
|
196
201
|
serialize(): U;
|
|
@@ -215,6 +220,13 @@ declare class SmpErrorResponse<T = any> extends SmpGenericResponse<T, SmpGeneric
|
|
|
215
220
|
static fromPlain(plain: unknown): SmpErrorResponse<any>;
|
|
216
221
|
}
|
|
217
222
|
|
|
223
|
+
declare class SmpErrorResponseWithStackTrace<T = any> extends SmpErrorResponse<T> {
|
|
224
|
+
stackTrace?: string;
|
|
225
|
+
static create<T>({ messages, stackTrace, ...opts }?: Partial<SmpErrorResponseCreateOpts<T>> & {
|
|
226
|
+
stackTrace?: string;
|
|
227
|
+
}): SmpErrorResponseWithStackTrace<T>;
|
|
228
|
+
}
|
|
229
|
+
|
|
218
230
|
declare const SMP_HEALTHZ: {
|
|
219
231
|
status: string;
|
|
220
232
|
};
|
|
@@ -726,6 +738,7 @@ declare class SmpCrypto {
|
|
|
726
738
|
static base64Decode(str: string): string;
|
|
727
739
|
static base64Encode(str: string): string;
|
|
728
740
|
static generateCorrelationId(): string;
|
|
741
|
+
static generateUuidV4(): string;
|
|
729
742
|
static md5(data: string): string;
|
|
730
743
|
static sha1(data: string): string;
|
|
731
744
|
static sha256(data: string): string;
|
|
@@ -938,7 +951,7 @@ declare class SmpCommonUtils {
|
|
|
938
951
|
static sprintf(str: string, ...argv: (string | number | symbol)[]): string;
|
|
939
952
|
static stripComments(html: string): string;
|
|
940
953
|
/**
|
|
941
|
-
* Strips all
|
|
954
|
+
* Strips all the html from string.
|
|
942
955
|
* @param html
|
|
943
956
|
* @param decodeEntities should decode entities? Default TRUE
|
|
944
957
|
*/
|
|
@@ -955,7 +968,6 @@ declare class SmpCommonUtils {
|
|
|
955
968
|
static toSnakeCase(s: string): string;
|
|
956
969
|
static toUpperSnakeCase(s: string): string;
|
|
957
970
|
static words(string: string, pattern?: RegExp): string[];
|
|
958
|
-
protected static _decodeHtmlEntities(value: string): string;
|
|
959
971
|
}
|
|
960
972
|
|
|
961
973
|
declare class SmpFilterException extends Error {
|
|
@@ -987,6 +999,7 @@ declare class SmpRegularExpressions {
|
|
|
987
999
|
static get LATIN_CHARS(): RegExp;
|
|
988
1000
|
static get LOCALE(): RegExp;
|
|
989
1001
|
static get NO_EMOJI_NO_PUNCTUATION(): RegExp;
|
|
1002
|
+
static get NO_HTML(): RegExp;
|
|
990
1003
|
static get PHONE_NUMBER(): RegExp;
|
|
991
1004
|
static get PHONE_NUMBER_BY_PREFIX(): Record<string, Record<string, RegExp>>;
|
|
992
1005
|
static get TAXCODE_BY_COUNTRY(): Record<string, Record<string, RegExp>>;
|
|
@@ -1013,6 +1026,6 @@ declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
|
|
|
1013
1026
|
*/
|
|
1014
1027
|
declare function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
|
|
1015
1028
|
|
|
1016
|
-
declare const VERSION: "2.
|
|
1029
|
+
declare const VERSION: "2.1.0";
|
|
1017
1030
|
|
|
1018
|
-
export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpAesCryptV2, 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 };
|
|
1031
|
+
export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpAesCryptV2, SmpApiCommonUtils, SmpBaseJwtToken, SmpBaseJwtTokenPlain, SmpBrowserCache, SmpCachedValue, SmpCommonUtils, SmpCrypto, type SmpDynamicFetchReturn, SmpErrorResponse, type SmpErrorResponseCreateOpts, SmpErrorResponseWithStackTrace, 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 };
|
|
@@ -13,7 +13,9 @@ interface SmpResponseMessageBase {
|
|
|
13
13
|
declare class SmpResponseMessage implements SmpResponseMessageBase {
|
|
14
14
|
protected _message: string;
|
|
15
15
|
protected _type: SmpResponseMessageTypes;
|
|
16
|
+
set message(value: string);
|
|
16
17
|
get message(): string;
|
|
18
|
+
set type(value: SmpResponseMessageTypes);
|
|
17
19
|
get type(): SmpResponseMessageTypes;
|
|
18
20
|
constructor(_message: string, _type?: SmpResponseMessageTypes);
|
|
19
21
|
static sanitizeMessages(messages: string | SmpResponseMessage | (SmpResponseMessage | string)[]): SmpResponseMessage[];
|
package/dist/cjs/zod.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var I=Object.create;var d=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var a=(t,e)=>d(t,"name",{value:e,configurable:!0});var C=(t,e)=>{for(var s in e)d(t,s,{get:e[s],enumerable:!0})},x=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of _(e))!g.call(t,m)&&m!==s&&d(t,m,{get:()=>e[m],enumerable:!(n=T(e,m))||n.enumerable});return t};var b=(t,e,s)=>(s=t!=null?I(h(t)):{},x(e||!t||!t.__esModule?d(s,"default",{value:t,enumerable:!0}):s,t)),S=t=>x(d({},"__esModule",{value:!0}),t);var O={};C(O,{SmpZodDateTime:()=>l,smpGenericResponseSchema:()=>w,smpResponseMessageSchema:()=>p,smpZodDateTime:()=>M});module.exports=S(O);var f=require("zod");var c=require("zod");var D=(function(t){return t.INFO="INFO",t.SUCCESS="SUCCESS",t.WARNING="WARNING",t.ERROR="ERROR",t})({});var p=c.z.object({message:c.z.string(),type:c.z.nativeEnum(D)});var w=f.z.object({data:f.z.unknown().optional(),messages:f.z.array(p).optional()});var o=b(require("zod"),1),u=require("ts-luxon");var l=class t extends o.default.ZodType{static{a(this,"SmpZodDateTime")}constructor(e){super({typeName:"SmpZodDateTime",coerce:e?.coerce??!1,checks:e?.checks??[]})}_parse(e){let s=this._getOrReturnCtx(e),n=s.data;if(this._def.coerce&&(n=this._coerceToDateTime(n),!this._isValidDateTime(n)))return o.default.addIssueToContext(s,{code:o.ZodIssueCode.invalid_type,expected:o.ZodParsedType.date,received:o.ZodParsedType.unknown,message:"Invalid date format"}),o.default.INVALID;if(!this._isValidDateTime(n)&&!this._def.coerce)return o.default.addIssueToContext(s,{code:o.ZodIssueCode.invalid_type,expected:o.ZodParsedType.date,received:o.ZodParsedType.unknown,message:"Input must be a valid DateTime object"}),o.default.INVALID;let m={min:a((i,r)=>{if(i.min&&r.toMillis()<i.min.toMillis())return{code:o.ZodIssueCode.too_small,minimum:i.min.toMillis(),type:"date",inclusive:!0,message:i.message??`Date must be \u2265 ${i.min.toISODate()}`}},"min"),max:a((i,r)=>{if(i.max&&r.toMillis()>i.max.toMillis())return{code:o.ZodIssueCode.too_big,maximum:i.max.toMillis(),type:"date",inclusive:!0,message:i.message??`Date must be \u2264 ${i.max.toISODate()}`}},"max"),between:a((i,r)=>{if(i.min&&i.max&&(r.toMillis()<i.min.toMillis()||r.toMillis()>i.max.toMillis()))return{code:o.ZodIssueCode.custom,message:i.message??`Date must be between ${i.min.toISODate()} and ${i.max.toISODate()}`}},"between")};for(let i of this._def.checks)if(this._isValidDateTime(n)){let r=m[i.kind](i,n);r&&o.default.addIssueToContext(s,r)}return s.common.issues.length>0?o.default.INVALID:o.default.OK(n)}between(e,s,n){return new t({...this._def,checks:[...this._def.checks,{kind:"between",min:e.toUTC(),max:s.toUTC(),message:n}]})}coerce(){return new t({...this._def,coerce:!0})}max(e,s){return new t({...this._def,checks:[...this._def.checks,{kind:"max",max:e.toUTC(),message:s}]})}min(e,s){return new t({...this._def,checks:[...this._def.checks,{kind:"min",min:e.toUTC(),message:s}]})}_coerceToDateTime(e){return this._isValidDateTime(e)?e:typeof e=="string"?u.DateTime.fromISO(e):typeof e=="number"?u.DateTime.fromMillis(e):e instanceof Date?u.DateTime.fromJSDate(e).toUTC():null}_isValidDateTime(e){return u.DateTime.isDateTime(e)&&e.isValid}},M=a((t={})=>new l({coerce:t.coerce??!1,checks:[]}),"smpZodDateTime");0&&(module.exports={SmpZodDateTime,smpGenericResponseSchema,smpResponseMessageSchema,smpZodDateTime});
|
|
2
2
|
//# sourceMappingURL=zod.cjs.map
|
package/dist/cjs/zod.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/zod.ts","../../src/shared/zod/smp-generic-response.schema.ts","../../src/shared/zod/smp-response-message.schema.ts","../../src/shared/api/smp-response-message-types.enum.ts","../../src/shared/zod/smp-zod-date-time.definition.ts"],"sourcesContent":["export * from \"./shared/zod/index.js\";\n","import {z, ZodTypeAny} from \"zod\";\n//\nimport {SmpGenericResponseBase} from \"../api/smp-generic-response-base.interface.js\";\nimport {smpResponseMessageSchema} from \"./smp-response-message.schema.js\";\n\nexport const smpGenericResponseSchema = z.object({\n data: z.unknown().optional(),\n messages: z.array(smpResponseMessageSchema).optional()\n} as Record<keyof SmpGenericResponseBase, ZodTypeAny>);\n","import {z, ZodTypeAny} from \"zod\";\n//\nimport {SmpResponseMessage} from \"../api/smp-response-message.class.js\";\nimport {SmpResponseMessageTypes} from \"../api/smp-response-message-types.enum.js\";\n\nexport const smpResponseMessageSchema = z.object({\n message: z.string(),\n type: z.nativeEnum(SmpResponseMessageTypes)\n} as Record<keyof SmpResponseMessage, ZodTypeAny>);\n","export enum SmpResponseMessageTypes {\n INFO = \"INFO\",\n SUCCESS = \"SUCCESS\",\n WARNING = \"WARNING\",\n ERROR = \"ERROR\"\n}\n","import z, {ZodTypeDef, ZodIssueCode, ParseInput, ParseContext, ParseReturnType, ZodParsedType} from \"zod\";\nimport {DateTime} from \"ts-luxon\";\n\ninterface SmpZodDateTimeCheck {\n kind: \"min\" | \"max\" | \"between\";\n min?: DateTime;\n max?: DateTime;\n message?: string;\n}\n\ninterface SmpZodDateTimeDef extends ZodTypeDef {\n coerce: boolean;\n checks: SmpZodDateTimeCheck[];\n typeName: \"SmpZodDateTime\";\n}\n\nexport class SmpZodDateTime extends z.ZodType<DateTime, SmpZodDateTimeDef> {\n // Constructor and other methods (between, coerce, max, min, _coerceToDateTime) remain the same as your latest version or my previous suggestions.\n // For brevity, only _parse is shown fully modified here. Ensure other parts of the class are consistent.\n\n constructor(def?: Partial<SmpZodDateTimeDef>) {\n super({\n typeName: \"SmpZodDateTime\",\n coerce: def?.coerce ?? false,\n checks: def?.checks ?? []\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n _parse(input: ParseInput): ParseReturnType<DateTime> {\n const ctx = this._getOrReturnCtx(input);\n let val = ctx.data;\n\n if (this._def.coerce) {\n val = this._coerceToDateTime(val); // Assuming _coerceToDateTime is implemented\n if (!(val instanceof DateTime) || !val.isValid) {\n z.addIssueToContext(ctx, { // Changed from ctx.addIssue\n code: ZodIssueCode.invalid_type,\n expected: ZodParsedType.date, // Using ZodParsedType.date\n received: ZodParsedType.unknown,\n path: ctx.path,\n message: \"Invalid date format\"\n });\n return z.INVALID;\n }\n }\n\n // Ensure val is a DateTime object before proceeding with checks if not coercing\n // or if coercion failed to produce a DateTime (though the above check should catch it)\n if (!(val instanceof DateTime) || !val.isValid) {\n // If not coercing, and it's not a valid DateTime, this is an invalid type.\n // This specific case might be implicitly handled if !this._def.coerce means val must already be DateTime.\n // However, adding an explicit check if not coercing can be safer.\n if (!this._def.coerce) {\n z.addIssueToContext(ctx, {\n code: ZodIssueCode.invalid_type,\n expected: ZodParsedType.date, // Or a custom type name if you prefer\n received: ZodParsedType.unknown, // Or more specific if possible\n path: ctx.path,\n message: \"Input must be a valid DateTime object\"\n });\n return z.INVALID;\n }\n // If coercion was supposed to happen, and we still don't have a valid DateTime,\n // the earlier check inside the `if (this._def.coerce)` block should have caught it.\n }\n\n\n const checkMap: Record<SmpZodDateTimeCheck[\"kind\"], (check: SmpZodDateTimeCheck, dateTimeVal: DateTime, parseCtx: ParseContext) => z.ZodIssue | undefined> = {\n min: (check, dateTimeVal, parseCtx) => {\n if (check.min && dateTimeVal < check.min) {\n return {\n code: ZodIssueCode.too_small,\n minimum: check.min.toMillis(), // Changed to number (milliseconds)\n type: \"date\", // Added type\n inclusive: true,\n message: check.message ?? `Date must be ≥ ${check.min.toISODate()}`,\n path: parseCtx.path\n };\n }\n return undefined;\n },\n max: (check, dateTimeVal, parseCtx) => {\n if (check.max && dateTimeVal > check.max) {\n return {\n code: ZodIssueCode.too_big,\n maximum: check.max.toMillis(), // Changed to number (milliseconds)\n type: \"date\", // Added type\n inclusive: true, // Added inclusive\n message: check.message ?? `Date must be ≤ ${check.max.toISODate()}`,\n path: parseCtx.path\n };\n }\n return undefined;\n },\n between: (check, dateTimeVal, parseCtx) => {\n if (check.min && check.max && (dateTimeVal < check.min || dateTimeVal > check.max)) {\n return {\n code: ZodIssueCode.custom,\n message: check.message ?? `Date must be between ${check.min.toISODate()} and ${check.max.toISODate()}`,\n path: parseCtx.path\n // Optionally, add params for more structured error data:\n // params: { min: check.min.toISO(), max: check.max.toISO() }\n };\n }\n return undefined;\n }\n };\n\n for (const check of this._def.checks) {\n // Ensure val is a DateTime before passing to checkMap functions\n // This is crucial if coercion didn't happen or didn't result in a DateTime.\n // The earlier checks should ideally ensure 'val' is a valid DateTime if it reached this point.\n if (val instanceof DateTime && val.isValid) {\n const issueData = checkMap[check.kind](check, val, ctx);\n if (issueData) {\n z.addIssueToContext(ctx, issueData); // Changed from ctx.addIssue\n }\n }\n else {\n // This case should ideally be caught earlier (e.g., if not coercing, or if coercion failed)\n // If it reaches here, it implies a logic flaw or an unexpected state.\n // For robustness, you might add a generic invalid_type issue here if 'val' is not a DateTime.\n // However, the checks at the beginning of _parse should prevent this.\n }\n }\n\n if (ctx.common.issues.length > 0) { // Check ctx.common.issues.length\n return z.INVALID;\n }\n\n return z.OK(val as DateTime); // Ensure the 'val' returned by OK is typed as DateTime\n }\n\n between(min: DateTime, max: DateTime, message?: string): this {\n return new SmpZodDateTime({\n ...this._def,\n checks: [...this._def.checks, {kind: \"between\", min: min.toUTC(), max: max.toUTC(), message}]\n }) as this;\n }\n\n coerce(): this {\n return new SmpZodDateTime({\n ...this._def,\n coerce: true\n }) as this;\n }\n\n max(max: DateTime, message?: string): this {\n return new SmpZodDateTime({\n ...this._def,\n checks: [...this._def.checks, {kind: \"max\", max: max.toUTC(), message}]\n }) as this;\n }\n\n min(min: DateTime, message?: string): this {\n return new SmpZodDateTime({\n ...this._def,\n checks: [...this._def.checks, {kind: \"min\", min: min.toUTC(), message}]\n }) as this;\n }\n\n // Coercion helper function (ensure it's robust as discussed previously)\n private _coerceToDateTime(val: any): DateTime | null {\n if (val instanceof DateTime && val.isValid) {\n return val; // Already valid DateTime\n }\n\n const coercionMap: Record<string, () => DateTime | null> = {\n string: () => DateTime.fromJSDate(new Date(val)),\n number: () => DateTime.fromMillis(val),\n object: () => DateTime.fromJSDate(val),\n default: () => null\n };\n\n return (coercionMap[typeof val] || coercionMap.default)();\n }\n}\n\nexport const smpZodDateTime = (opts: { coerce?: boolean } = {}) => {\n return new SmpZodDateTime({\n coerce: opts.coerce ?? false,\n checks: []\n });\n};\n"],"mappings":"6mBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,6BAAAC,EAAA,6BAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAN,GCAA,IAAAO,EAA4B,eCA5B,IAAAC,EAA4B,eCArB,IAAKC,GAAAA,SAAAA,EAAAA,8EAAAA,QDKL,IAAMC,EAA2BC,IAAEC,OAAO,CAC7CC,QAASF,IAAEG,OAAM,EACjBC,KAAMJ,IAAEK,WAAWC,CAAAA,CACvB,CAAA,EDHO,IAAMC,EAA2BC,IAAEC,OAAO,CAC7CC,KAAMF,IAAEG,QAAO,EAAGC,SAAQ,EAC1BC,SAAUL,IAAEM,MAAMC,CAAAA,EAA0BH,SAAQ,CACxD,CAAA,EGRA,IAAAI,EAAoG,oBACpGC,EAAuB,oBAehB,IAAMC,EAAN,MAAMA,UAAuBC,EAAAA,QAAEC,OAAO,CAhB7C,MAgB6C,CAAAC,EAAA,uBAIzC,YAAYC,EAAkC,CAC1C,MAAM,CACFC,SAAU,iBACVC,OAAQF,GAAKE,QAAU,GACvBC,OAAQH,GAAKG,QAAU,CAAA,CAC3B,CAAA,CACJ,CAGAC,OAAOC,EAA8C,CACjD,IAAMC,EAAM,KAAKC,gBAAgBF,CAAAA,EAC7BG,EAAMF,EA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AIxB,QAAAA,CAAO,EACzE,CAAA,CACJ,CAGQb,kBAAkBH,EAA2B,CACjD,GAAIA,aAAeI,YAAYJ,EAAIK,QAC/B,OAAOL,EAGX,IAAMyC,EAAqD,CACvDC,OAAQnD,EAAA,IAAMa,WAASuC,WAAW,IAAIC,KAAK5C,CAAAA,CAAAA,EAAnC,UACR6C,OAAQtD,EAAA,IAAMa,WAAS0C,WAAW9C,CAAAA,EAA1B,UACR+C,OAAQxD,EAAA,IAAMa,WAASuC,WAAW3C,CAAAA,EAA1B,UACRgD,QAASzD,EAAA,IAAM,KAAN,UACb,EAEA,OAAQkD,EAAY,OAAOzC,CAAAA,GAAQyC,EAAYO,SAAM,CACzD,CACJ,EAEaC,EAAiB1D,EAAA,CAAC2D,EAA6B,CAAC,IAClD,IAAI9D,EAAe,CACtBM,OAAQwD,EAAKxD,QAAU,GACvBC,OAAQ,CAAA,CACZ,CAAA,EAJ0B","names":["zod_exports","__export","SmpZodDateTime","smpGenericResponseSchema","smpResponseMessageSchema","smpZodDateTime","__toCommonJS","import_zod","import_zod","SmpResponseMessageTypes","smpResponseMessageSchema","z","object","message","string","type","nativeEnum","SmpResponseMessageTypes","smpGenericResponseSchema","z","object","data","unknown","optional","messages","array","smpResponseMessageSchema","import_zod","import_ts_luxon","SmpZodDateTime","z","ZodType","__name","def","typeName","coerce","checks","_parse","input","ctx","_getOrReturnCtx","val","data","_def","_coerceToDateTime","DateTime","isValid","addIssueToContext","code","ZodIssueCode","invalid_type","expected","ZodParsedType","date","received","unknown","path","message","INVALID","checkMap","min","check","dateTimeVal","parseCtx","too_small","minimum","toMillis","type","inclusive","toISODate","max","too_big","maximum","between","custom","issueData","kind","common","issues","length","OK","toUTC","coercionMap","string","fromJSDate","Date","number","fromMillis","object","default","smpZodDateTime","opts"]}
|
|
1
|
+
{"version":3,"sources":["../../src/zod.ts","../../src/shared/zod/smp-generic-response.schema.ts","../../src/shared/zod/smp-response-message.schema.ts","../../src/shared/api/smp-response-message-types.enum.ts","../../src/shared/zod/smp-zod-date-time.definition.ts"],"sourcesContent":["export * from \"./shared/zod/index.js\";\n","import {z, ZodTypeAny} from \"zod\";\n//\nimport {SmpGenericResponseBase} from \"../api/smp-generic-response-base.interface.js\";\nimport {smpResponseMessageSchema} from \"./smp-response-message.schema.js\";\n\nexport const smpGenericResponseSchema = z.object({\n data: z.unknown().optional(),\n messages: z.array(smpResponseMessageSchema).optional()\n} as Record<keyof SmpGenericResponseBase, ZodTypeAny>);\n","import {z, ZodTypeAny} from \"zod\";\n//\nimport {SmpResponseMessage} from \"../api/smp-response-message.class.js\";\nimport {SmpResponseMessageTypes} from \"../api/smp-response-message-types.enum.js\";\n\nexport const smpResponseMessageSchema = z.object({\n message: z.string(),\n type: z.nativeEnum(SmpResponseMessageTypes)\n} as Record<keyof SmpResponseMessage, ZodTypeAny>);\n","export enum SmpResponseMessageTypes {\n INFO = \"INFO\",\n SUCCESS = \"SUCCESS\",\n WARNING = \"WARNING\",\n ERROR = \"ERROR\"\n}\n","import z, {ZodTypeDef, ZodIssueCode, ParseInput, ParseReturnType, ZodParsedType, type IssueData} from \"zod\";\nimport {DateTime} from \"ts-luxon\";\n\ninterface SmpZodDateTimeCheck {\n kind: \"min\" | \"max\" | \"between\";\n min?: DateTime;\n max?: DateTime;\n message?: string;\n}\n\ninterface SmpZodDateTimeDef extends ZodTypeDef {\n coerce: boolean;\n checks: SmpZodDateTimeCheck[];\n typeName: \"SmpZodDateTime\";\n}\n\nexport class SmpZodDateTime extends z.ZodType<DateTime, SmpZodDateTimeDef> {\n // Constructor and other methods (between, coerce, max, min, _coerceToDateTime) remain the same as your latest version or my previous suggestions.\n // For brevity, only _parse is shown fully modified here. Ensure other parts of the class are consistent.\n\n constructor(def?: Partial<SmpZodDateTimeDef>) {\n super({\n typeName: \"SmpZodDateTime\",\n coerce: def?.coerce ?? false,\n checks: def?.checks ?? []\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n _parse(input: ParseInput): ParseReturnType<DateTime> {\n const ctx = this._getOrReturnCtx(input);\n let val = ctx.data;\n\n if (this._def.coerce) {\n val = this._coerceToDateTime(val);\n if (!this._isValidDateTime(val)) {\n z.addIssueToContext(ctx, {\n code: ZodIssueCode.invalid_type,\n expected: ZodParsedType.date,\n received: ZodParsedType.unknown,\n message: \"Invalid date format\"\n });\n return z.INVALID;\n }\n }\n\n if (!this._isValidDateTime(val)) {\n if (!this._def.coerce) {\n z.addIssueToContext(ctx, {\n code: ZodIssueCode.invalid_type,\n expected: ZodParsedType.date,\n received: ZodParsedType.unknown,\n message: \"Input must be a valid DateTime object\"\n });\n return z.INVALID;\n }\n }\n\n\n const checkMap: Record<SmpZodDateTimeCheck[\"kind\"], (check: SmpZodDateTimeCheck, dateTimeVal: DateTime) => IssueData | undefined> = {\n min: (check, dateTimeVal) => {\n if (check.min && dateTimeVal.toMillis() < check.min.toMillis()) {\n return {\n code: ZodIssueCode.too_small,\n minimum: check.min.toMillis(),\n type: \"date\",\n inclusive: true,\n message: check.message ?? `Date must be ≥ ${check.min.toISODate()}`\n };\n }\n return undefined;\n },\n max: (check, dateTimeVal) => {\n if (check.max && dateTimeVal.toMillis() > check.max.toMillis()) {\n return {\n code: ZodIssueCode.too_big,\n maximum: check.max.toMillis(),\n type: \"date\",\n inclusive: true,\n message: check.message ?? `Date must be ≤ ${check.max.toISODate()}`\n };\n }\n return undefined;\n },\n between: (check, dateTimeVal) => {\n if (\n check.min\n && check.max\n && (dateTimeVal.toMillis() < check.min.toMillis() || dateTimeVal.toMillis() > check.max.toMillis())\n ) {\n return {\n code: ZodIssueCode.custom,\n message: check.message ?? `Date must be between ${check.min.toISODate()} and ${check.max.toISODate()}`\n };\n }\n return undefined;\n }\n };\n\n for (const check of this._def.checks) {\n if (this._isValidDateTime(val)) {\n const issueData = checkMap[check.kind](check, val);\n if (issueData) {\n z.addIssueToContext(ctx, issueData);\n }\n }\n }\n\n if (ctx.common.issues.length > 0) {\n return z.INVALID;\n }\n\n return z.OK(val);\n }\n\n between(min: DateTime, max: DateTime, message?: string): this {\n return new SmpZodDateTime({\n ...this._def,\n checks: [...this._def.checks, {kind: \"between\", min: min.toUTC(), max: max.toUTC(), message}]\n }) as this;\n }\n\n coerce(): this {\n return new SmpZodDateTime({\n ...this._def,\n coerce: true\n }) as this;\n }\n\n max(max: DateTime, message?: string): this {\n return new SmpZodDateTime({\n ...this._def,\n checks: [...this._def.checks, {kind: \"max\", max: max.toUTC(), message}]\n }) as this;\n }\n\n min(min: DateTime, message?: string): this {\n return new SmpZodDateTime({\n ...this._def,\n checks: [...this._def.checks, {kind: \"min\", min: min.toUTC(), message}]\n }) as this;\n }\n\n private _coerceToDateTime(val: unknown): DateTime | null {\n if (this._isValidDateTime(val)) {\n return val;\n }\n\n if (typeof val === \"string\") {\n return DateTime.fromISO(val);\n }\n\n if (typeof val === \"number\") {\n return DateTime.fromMillis(val);\n }\n\n if (val instanceof Date) {\n return DateTime.fromJSDate(val).toUTC();\n }\n\n return null;\n }\n\n private _isValidDateTime(val: unknown): val is DateTime {\n return DateTime.isDateTime(val) && val.isValid;\n }\n}\n\nexport const smpZodDateTime = (opts: { coerce?: boolean } = {}) => {\n return new SmpZodDateTime({\n coerce: opts.coerce ?? false,\n checks: []\n });\n};\n"],"mappings":"6mBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,6BAAAC,EAAA,6BAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAN,GCAA,IAAAO,EAA4B,eCA5B,IAAAC,EAA4B,eCArB,IAAKC,GAAAA,SAAAA,EAAAA,8EAAAA,QDKL,IAAMC,EAA2BC,IAAEC,OAAO,CAC7CC,QAASF,IAAEG,OAAM,EACjBC,KAAMJ,IAAEK,WAAWC,CAAAA,CACvB,CAAA,EDHO,IAAMC,EAA2BC,IAAEC,OAAO,CAC7CC,KAAMF,IAAEG,QAAO,EAAGC,SAAQ,EAC1BC,SAAUL,IAAEM,MAAMC,CAAAA,EAA0BH,SAAQ,CAC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EAAe,CACtB,GAAG,KAAKc,KACRP,OAAQ,IAAI,KAAKO,KAAKP,OAAQ,CAACqC,KAAM,MAAON,IAAKA,EAAIW,MAAK,EAAIvB,QAAAA,CAAO,EACzE,CAAA,CACJ,CAEAG,IAAIA,EAAeH,EAAwB,CACvC,OAAO,IAAI1B,EAAe,CACtB,GAAG,KAAKc,KACRP,OAAQ,IAAI,KAAKO,KAAKP,OAAQ,CAACqC,KAAM,MAAOf,IAAKA,EAAIoB,MAAK,EAAIvB,QAAAA,CAAO,EACzE,CAAA,CACJ,CAEQX,kBAAkBH,EAA+B,CACrD,OAAI,KAAKI,iBAAiBJ,CAAAA,EACfA,EAGP,OAAOA,GAAQ,SACRsC,WAASC,QAAQvC,CAAAA,EAGxB,OAAOA,GAAQ,SACRsC,WAASE,WAAWxC,CAAAA,EAG3BA,aAAeyC,KACRH,WAASI,WAAW1C,CAAAA,EAAKqC,MAAK,EAGlC,IACX,CAEQjC,iBAAiBJ,EAA+B,CACpD,OAAOsC,WAASK,WAAW3C,CAAAA,GAAQA,EAAI4C,OAC3C,CACJ,EAEaC,EAAiBtD,EAAA,CAACuD,EAA6B,CAAC,IAClD,IAAI1D,EAAe,CACtBM,OAAQoD,EAAKpD,QAAU,GACvBC,OAAQ,CAAA,CACZ,CAAA,EAJ0B","names":["zod_exports","__export","SmpZodDateTime","smpGenericResponseSchema","smpResponseMessageSchema","smpZodDateTime","__toCommonJS","import_zod","import_zod","SmpResponseMessageTypes","smpResponseMessageSchema","z","object","message","string","type","nativeEnum","SmpResponseMessageTypes","smpGenericResponseSchema","z","object","data","unknown","optional","messages","array","smpResponseMessageSchema","import_zod","import_ts_luxon","SmpZodDateTime","z","ZodType","__name","def","typeName","coerce","checks","_parse","input","ctx","_getOrReturnCtx","val","data","_def","_coerceToDateTime","_isValidDateTime","addIssueToContext","code","ZodIssueCode","invalid_type","expected","ZodParsedType","date","received","unknown","message","INVALID","checkMap","min","check","dateTimeVal","toMillis","too_small","minimum","type","inclusive","toISODate","max","too_big","maximum","between","custom","issueData","kind","common","issues","length","OK","toUTC","DateTime","fromISO","fromMillis","Date","fromJSDate","isDateTime","isValid","smpZodDateTime","opts"]}
|
package/dist/cjs/zod.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import z$1, { z, ZodTypeDef, ParseInput, ParseReturnType } from 'zod';
|
|
2
|
-
import { b as SmpGenericResponseBase, S as SmpResponseMessage } from './smp-generic-response-base.interface-
|
|
2
|
+
import { b as SmpGenericResponseBase, S as SmpResponseMessage } from './smp-generic-response-base.interface-BSdPo_xm.cjs';
|
|
3
3
|
import { DateTime } from 'ts-luxon';
|
|
4
4
|
|
|
5
5
|
declare const smpGenericResponseSchema: z.ZodObject<Record<keyof SmpGenericResponseBase<any>, z.ZodTypeAny>, "strip", z.ZodTypeAny, {
|
|
@@ -37,6 +37,7 @@ declare class SmpZodDateTime extends z$1.ZodType<DateTime, SmpZodDateTimeDef> {
|
|
|
37
37
|
max(max: DateTime, message?: string): this;
|
|
38
38
|
min(min: DateTime, message?: string): this;
|
|
39
39
|
private _coerceToDateTime;
|
|
40
|
+
private _isValidDateTime;
|
|
40
41
|
}
|
|
41
42
|
declare const smpZodDateTime: (opts?: {
|
|
42
43
|
coerce?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=Object.create;var e=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(b,a)=>e(b,"name",{value:a,configurable:!0});var n=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports);var l=(b,a,c,f)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!k.call(b,d)&&d!==c&&e(b,d,{get:()=>a[d],enumerable:!(f=h(a,d))||f.enumerable});return b};var o=(b,a,c)=>(c=b!=null?g(j(b)):{},l(a||!b||!b.__esModule?e(c,"default",{value:b,enumerable:!0}):c,b));export{m as a,n as b,o as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as p}from"./chunk-
|
|
1
|
+
import{a as p}from"./chunk-7X4DHW36.js";var e=class{static{p(this,"SmpAbstractCacheStrategy")}};function r(n){return typeof n=="object"&&n!==null&&"value"in n&&"expiry"in n&&typeof n.expiry=="number"}p(r,"smpIsSmpCachedValue");export{e as a,r as b};
|
package/dist/esm/dynamo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-7X4DHW36.js";import{DynamoDB as s}from"@aws-sdk/client-dynamodb";import{marshall as c,unmarshall as m}from"@aws-sdk/util-dynamodb";import{SmpLoggerMethods as h}from"@tonysamperi/logger";var _=(function(r){return r.CouldNotDelete="ERR_COULD_NOT_DELETE",r.CouldNotRead="ERR_COULD_NOT_READ",r.CouldNotWrite="ERR_COULD_NOT_WRITE",r.ConditionalCheckFailedException="ERR_DUPE_TOKEN",r})(_||{}),l=class{static{a(this,"SmpDynamoService")}_config;_tableName;get marshall(){return c}get unmarshall(){return m}_db=new s([this._buildConfig()]);_logger=new h;constructor(e,o){this._config=e,this._tableName=o}_buildConfig(){return this._config}_delete(e,o=this._tableName,i){let n={TableName:o,Key:this.marshall(e),...i};return this._db.deleteItem(n).catch(t=>(this._logger.error("DynamoActionTokensService: couldn't write token to DB",t),Promise.reject(_[t.code]||"ERR_COULD_NOT_DELETE")))}_read(e,o=this._tableName,i){let n={TableName:o,Key:this.marshall(e),...i};return this._db.getItem(n).catch(t=>(this._logger.error("DynamoActionTokensService: couldn't write token to DB",t),Promise.reject(_[t.code]||"ERR_COULD_NOT_READ")))}_write(e,o=this._tableName,i){let n={TableName:o,Item:this.marshall(e),...i};return this._db.putItem(n).catch(t=>(this._logger.error("DynamoActionTokensService: couldn't write token to DB",t),Promise.reject(_[t.code]||"ERR_COULD_NOT_WRITE")))}};export{l as SmpDynamoService};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
declare namespace smpEslintPlugin {
|
|
2
|
+
namespace meta {
|
|
3
|
+
let name: string;
|
|
4
|
+
}
|
|
5
|
+
let rules: {
|
|
6
|
+
"member-ordering-autofix": {
|
|
7
|
+
meta: {
|
|
8
|
+
type: string;
|
|
9
|
+
docs: {
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
fixable: string;
|
|
13
|
+
messages: {
|
|
14
|
+
sort: string;
|
|
15
|
+
};
|
|
16
|
+
schema: never[];
|
|
17
|
+
};
|
|
18
|
+
create(context: any): {
|
|
19
|
+
ClassDeclaration: (node: any) => void;
|
|
20
|
+
ClassExpression: (node: any) => void;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
"require-js-extension": {
|
|
24
|
+
meta: {
|
|
25
|
+
/** @type {"problem"} */
|
|
26
|
+
type: "problem";
|
|
27
|
+
/** @type {"code"} */
|
|
28
|
+
fixable: "code";
|
|
29
|
+
docs: {
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
schema: never[];
|
|
33
|
+
messages: {
|
|
34
|
+
missingJsExtension: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/** @param {SmpEslintRuleContext} context */
|
|
38
|
+
create(context: SmpEslintRuleContext): {
|
|
39
|
+
ImportDeclaration?: undefined;
|
|
40
|
+
ExportAllDeclaration?: undefined;
|
|
41
|
+
/** @param {{source?: SmpEslintSourceNode}} node */
|
|
42
|
+
ExportNamedDeclaration?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
ImportDeclaration: (node: SmpEslintAstNode) => void;
|
|
45
|
+
ExportAllDeclaration: (node: SmpEslintAstNode) => void;
|
|
46
|
+
/** @param {{source?: SmpEslintSourceNode}} node */
|
|
47
|
+
ExportNamedDeclaration(node: {
|
|
48
|
+
source?: SmpEslintSourceNode;
|
|
49
|
+
}): void;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
declare namespace smpEslintRecommendedConfig {
|
|
55
|
+
export let files: string[];
|
|
56
|
+
export namespace plugins {
|
|
57
|
+
export { smpEslintPlugin as smp };
|
|
58
|
+
}
|
|
59
|
+
let rules_1: {
|
|
60
|
+
/** @type {"error"} */
|
|
61
|
+
"smp/member-ordering-autofix": "error";
|
|
62
|
+
/** @type {"error"} */
|
|
63
|
+
"smp/require-js-extension": "error";
|
|
64
|
+
};
|
|
65
|
+
export { rules_1 as rules };
|
|
66
|
+
}
|
|
67
|
+
type SmpEslintRuleFix = {
|
|
68
|
+
range: [number, number];
|
|
69
|
+
text: string;
|
|
70
|
+
};
|
|
71
|
+
type SmpEslintFixer = {
|
|
72
|
+
insertTextBeforeRange(range: [number, number], text: string): SmpEslintRuleFix;
|
|
73
|
+
};
|
|
74
|
+
type SmpEslintSourceNode = {
|
|
75
|
+
value: unknown;
|
|
76
|
+
range: [number, number];
|
|
77
|
+
};
|
|
78
|
+
type SmpEslintAstNode = {
|
|
79
|
+
source: SmpEslintSourceNode;
|
|
80
|
+
};
|
|
81
|
+
type SmpEslintRuleContext = {
|
|
82
|
+
filename?: string;
|
|
83
|
+
getFilename(): string;
|
|
84
|
+
report(descriptor: {
|
|
85
|
+
node: SmpEslintSourceNode;
|
|
86
|
+
messageId: "missingJsExtension";
|
|
87
|
+
data: {
|
|
88
|
+
source: string;
|
|
89
|
+
};
|
|
90
|
+
fix(fixer: SmpEslintFixer): SmpEslintRuleFix;
|
|
91
|
+
}): void;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {"off" | "warn" | "error" | 0 | 1 | 2} SmpEslintSeverity
|
|
96
|
+
* @typedef {SmpEslintSeverity | [SmpEslintSeverity, ...unknown[]]} SmpEslintRuleConfig
|
|
97
|
+
* @typedef {Record<string, SmpEslintRuleConfig>} SmpEslintRules
|
|
98
|
+
*/
|
|
99
|
+
/** @type {SmpEslintRules} */
|
|
100
|
+
declare const smpMemberOrderingRules: SmpEslintRules;
|
|
101
|
+
/** @type {SmpEslintRules} */
|
|
102
|
+
declare const smpNamingConventionRules: SmpEslintRules;
|
|
103
|
+
type SmpEslintSeverity = "off" | "warn" | "error" | 0 | 1 | 2;
|
|
104
|
+
type SmpEslintRuleConfig = SmpEslintSeverity | [SmpEslintSeverity, ...unknown[]];
|
|
105
|
+
type SmpEslintRules = Record<string, SmpEslintRuleConfig>;
|
|
106
|
+
|
|
107
|
+
export { smpEslintPlugin, smpEslintRecommendedConfig, smpMemberOrderingRules, smpNamingConventionRules };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as n}from"./chunk-7X4DHW36.js";function g(m){let p=m.classes,y=p.memberTypes;return{meta:{type:"suggestion",docs:{description:"Automatically sorts safe, alphabetically ordered class members."},fixable:"code",messages:{sort:"Sort this class member group alphabetically."},schema:[]},create(c){let o=c.sourceCode,s=n(e=>{if(p.order!=="alphabetically"||e.type!=="MethodDefinition"||e.decorators?.length||!["method","get","set"].includes(e.kind)||!["Identifier","PrivateIdentifier"].includes(e.key.type))return;let r=e.accessibility??"public",l=e.static?"static":"instance",a=`${r}-${l}-${e.kind}`,t=y.findIndex(i=>Array.isArray(i)?i.includes(a):i===a);if(t!==-1)return{groupIndex:t,member:e,name:e.key.name}},"getSortableMember"),u=n(e=>{if(e.length<2)return;let r=[...e].sort((t,i)=>t.name<i.name?-1:t.name>i.name?1:0);if(r.every(({member:t},i)=>t===e[i].member))return;let l=e[0].member,a=e[e.length-1].member;c.report({node:l,messageId:"sort",fix(t){return t.replaceTextRange([e[0].start,a.range[1]],r.map(({member:i,start:h})=>o.text.slice(h,i.range[1])).join(""))}})},"reportIfUnsorted"),d=n(e=>{let r=[],l=e.body.range[0]+1;e.body.body.forEach(a=>{let t=s(a);(!t||r.length&&t.groupIndex!==r[0].groupIndex)&&(u(r),r=[]),t&&r.push({...t,start:l}),l=a.range[1]}),u(r)},"visitClass");return{ClassDeclaration:d,ClassExpression:d}}}}n(g,"smpMemberOrderingAutofixRule");var f={"@typescript-eslint/member-ordering":["error",{default:{order:"alphabetically",memberTypes:[["set","get"]]},classes:{order:"alphabetically",memberTypes:[["public-static-set","public-static-get"],["protected-static-set","protected-static-get"],["private-static-set","private-static-get"],"public-static-field","protected-static-field","private-static-field",["public-decorated-set","public-decorated-get","public-instance-set","public-instance-get"],["protected-decorated-set","protected-decorated-get","protected-instance-set","protected-instance-get"],["private-decorated-set","private-decorated-get","private-instance-set","private-instance-get"],"public-field","protected-field","private-field","constructor","public-static-method","protected-static-method","private-static-method","public-instance-method","protected-instance-method","private-instance-method"]}}]},C={"@typescript-eslint/naming-convention":["error",{selector:"default",format:["camelCase"]},{selector:"objectLiteralProperty",format:null,modifiers:["requiresQuotes"]},{selector:"objectLiteralProperty",format:["camelCase","snake_case","PascalCase"]},{selector:"variable",format:["camelCase"],leadingUnderscore:"forbid"},{selector:"variable",modifiers:["exported"],format:["camelCase","UPPER_CASE","PascalCase"],leadingUnderscore:"forbid"},{selector:"parameter",format:["camelCase"],leadingUnderscore:"forbid"},{selector:"parameter",modifiers:["unused"],format:["camelCase"],leadingUnderscore:"require",trailingUnderscore:"require"},{selector:"memberLike",modifiers:["public","static","readonly"],format:["UPPER_CASE"],leadingUnderscore:"forbid"},{selector:"memberLike",modifiers:["protected","static","readonly"],format:["UPPER_CASE"],leadingUnderscore:"require"},{selector:"memberLike",modifiers:["private","static","readonly"],format:["UPPER_CASE"],leadingUnderscore:"require"},{selector:"memberLike",modifiers:["public"],format:["camelCase","PascalCase"],leadingUnderscore:"forbid"},{selector:"memberLike",modifiers:["protected"],format:["camelCase"],leadingUnderscore:"require"},{selector:"memberLike",modifiers:["private"],format:["camelCase"],leadingUnderscore:"require"},{selector:"classicAccessor",modifiers:["static","public"],format:["UPPER_CASE"],leadingUnderscore:"forbid"},{selector:"classicAccessor",modifiers:["static","protected"],format:["UPPER_CASE"],leadingUnderscore:"require"},{selector:"classicAccessor",modifiers:["static","private"],format:["UPPER_CASE"],leadingUnderscore:"require"},{selector:"typeLike",format:["PascalCase"]},{selector:"enumMember",format:["UPPER_CASE","PascalCase","camelCase"]}]};var E={meta:{type:"problem",fixable:"code",docs:{description:"Require .js extension for relative imports/exports in TypeScript files"},schema:[],messages:{missingJsExtension:"Relative path '{{source}}' must include '.js' extension."}},create(m){let p=m.filename||m.getFilename();if(!/\.(ts|tsx|mts|cts)$/.test(p))return{};let c=n(o=>{let s=o.source?.value;typeof s=="string"&&(!s.startsWith("./")&&!s.startsWith("../")||s.endsWith(".js")||s.endsWith(".mjs")||s.endsWith(".cjs")||s.endsWith(".json")||m.report({node:o.source,messageId:"missingJsExtension",data:{source:s},fix(u){let d=o.source.range[1]-1;return u.insertTextBeforeRange([d,d],".js")}}))},"checkNode");return{ImportDeclaration:c,ExportAllDeclaration:c,ExportNamedDeclaration(o){o.source&&c(o)}}}},P=g(f["@typescript-eslint/member-ordering"][1]),b={meta:{name:"@tonysamperi/ts-mapi-core"},rules:{"member-ordering-autofix":P,"require-js-extension":E}},x={files:["**/*.ts","**/*.tsx","**/*.mts","**/*.cts"],plugins:{smp:b},rules:{"smp/member-ordering-autofix":"error","smp/require-js-extension":"error"}};export{b as smpEslintPlugin,x as smpEslintRecommendedConfig,f as smpMemberOrderingRules,C as smpNamingConventionRules};
|
package/dist/esm/firebase.d.ts
CHANGED
|
@@ -9,20 +9,23 @@ interface SmpFirebaseServiceConfig {
|
|
|
9
9
|
logger?: SmpLoggerMethods;
|
|
10
10
|
popupFallsBackToRedirect?: boolean;
|
|
11
11
|
socialLoginUxMode?: SmpSocialSignInUxModes;
|
|
12
|
+
tenantId?: string;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
declare class
|
|
15
|
-
static
|
|
16
|
-
protected static _instance?: SmpFirebaseService;
|
|
15
|
+
declare class SmpFirebaseClient {
|
|
16
|
+
protected static _instanceCounter: number;
|
|
17
17
|
get config(): FirebaseOptions;
|
|
18
18
|
get enabledSocials(): SmpSocialSignInKeys[];
|
|
19
19
|
get loggedUser(): User | void;
|
|
20
20
|
get providersRelation(): Record<string, SmpSocialSignInKeys>;
|
|
21
21
|
get socialLoginUXMode(): SmpSocialSignInUxModes;
|
|
22
22
|
get storedUserKey(): string;
|
|
23
|
-
|
|
23
|
+
get tenantId(): string | null;
|
|
24
24
|
protected readonly _app: FirebaseApp;
|
|
25
|
+
protected readonly _appId: string;
|
|
26
|
+
protected readonly _auth: Auth;
|
|
25
27
|
protected readonly _config: FirebaseOptions;
|
|
28
|
+
protected readonly _defaultTenantId?: string;
|
|
26
29
|
protected readonly _enabledSocials: SmpSocialSignInKeys[];
|
|
27
30
|
protected _loggedUser?: User | void;
|
|
28
31
|
protected _logger: SmpLoggerMethods;
|
|
@@ -30,9 +33,10 @@ declare class SmpFirebaseService {
|
|
|
30
33
|
protected _popupFallsBackToRedirect: boolean;
|
|
31
34
|
protected _providers: Record<SmpSocialSignInKeys, AuthProvider>;
|
|
32
35
|
protected _socialLoginUxMode: SmpSocialSignInUxModes;
|
|
36
|
+
protected _storedUserKey: string;
|
|
33
37
|
constructor(firebaseOptions: FirebaseOptions, config: SmpFirebaseServiceConfig);
|
|
34
|
-
static init(firebaseOptions: FirebaseOptions, config: SmpFirebaseServiceConfig): SmpFirebaseService;
|
|
35
38
|
addAuthStateChangedCallback(cb: (userOrNull: User | null) => void): () => void;
|
|
39
|
+
addIdTokenChangedCallback(callback: (user: User | null) => void): () => void;
|
|
36
40
|
checkActionCode(code: string): Promise<ActionCodeInfo>;
|
|
37
41
|
confirmPasswordReset(code: string, newPassword: string): Promise<void>;
|
|
38
42
|
fetchSignInMethodsForEmail(email: string): Promise<SmpSocialSignInKeys[] | "password">;
|
|
@@ -53,10 +57,20 @@ declare class SmpFirebaseService {
|
|
|
53
57
|
verifyIdToken(): Promise<IdTokenResult | void>;
|
|
54
58
|
protected _buildProviders(): void;
|
|
55
59
|
protected _expandDifferentCredential(err: any): Promise<void>;
|
|
60
|
+
protected _generateAppId(): string;
|
|
56
61
|
protected _readStoredUser(): User | void;
|
|
62
|
+
protected _resolveApp(firebaseOptions: FirebaseOptions): FirebaseApp;
|
|
63
|
+
protected _setTenant(tenantId?: string): void;
|
|
57
64
|
protected _signInWithProvider<T extends AuthProvider = AuthProvider>(provider: T, uxMode?: SmpSocialSignInUxModes): Promise<User | void>;
|
|
58
65
|
protected _updateLocalUser(user: User | void): void;
|
|
59
66
|
protected _watchAuthState(): void;
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
|
|
69
|
+
declare class SmpFirebaseService extends SmpFirebaseClient {
|
|
70
|
+
static get INSTANCE(): SmpFirebaseService;
|
|
71
|
+
protected static _instance?: SmpFirebaseService;
|
|
72
|
+
constructor(firebaseOptions: FirebaseOptions, config: SmpFirebaseServiceConfig);
|
|
73
|
+
static init(firebaseOptions: FirebaseOptions, config: SmpFirebaseServiceConfig): SmpFirebaseService;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { SmpFirebaseClient, SmpFirebaseService, type SmpFirebaseServiceConfig };
|
package/dist/esm/firebase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as s,b as
|
|
1
|
+
import{a as s,b as n,c as d}from"./chunk-DIVAYUSN.js";import{a as o}from"./chunk-7X4DHW36.js";import{SmpLoggerMethods as c}from"@tonysamperi/logger";import{getApp as g,getApps as u,initializeApp as p}from"firebase/app";import{browserLocalPersistence as _,browserSessionPersistence as m,EmailAuthProvider as f,FacebookAuthProvider as I,GoogleAuthProvider as P,OAuthProvider as U,checkActionCode as E,confirmPasswordReset as b,fetchSignInMethodsForEmail as S,getAuth as w,getRedirectResult as A,reauthenticateWithCredential as C,sendEmailVerification as F,sendPasswordResetEmail as v,setPersistence as T,signInWithCustomToken as R,signInWithEmailAndPassword as k,signInWithPopup as L,signInWithRedirect as O,signOut as x,updatePassword as y,updateProfile as M}from"firebase/auth";var h=class a{static{o(this,"SmpFirebaseClient")}static _instanceCounter=0;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 this._storedUserKey}get tenantId(){return this._auth.tenantId||null}_app;_appId;_auth;_config;_defaultTenantId;_enabledSocials=[];_loggedUser;_logger;_popupErrors=0;_popupFallsBackToRedirect;_providers;_socialLoginUxMode=n.POPUP;_storedUserKey;constructor(e,t){this._appId=this._generateAppId(),this._config=e,this._defaultTenantId=t.tenantId,this._storedUserKey=t.tenantId?`firebaseUser::${t.tenantId}`:"firebaseUser",this._enabledSocials=t.enabledSocials||[],this._socialLoginUxMode=t.socialLoginUxMode||n.POPUP,this._popupFallsBackToRedirect=!!t.popupFallsBackToRedirect,this._buildProviders(),this._logger=t.logger||new c,this._app=this._resolveApp(e),this._auth=w(this._app),this._setTenant(this._defaultTenantId),this._watchAuthState()}addAuthStateChangedCallback(e){return this._auth.onAuthStateChanged(t=>{e(t||this.loggedUser||null)})}addIdTokenChangedCallback(e){return this._auth.onIdTokenChanged(e)}checkActionCode(e){return E(this._auth,e)}confirmPasswordReset(e,t){return b(this._auth,e,t)}fetchSignInMethodsForEmail(e){return S(this._auth,e).then(t=>t.map(r=>this.providersRelation[r]||r))}getRedirectResult(){return A(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 v(this._auth,e,{url:t})}setPersistence(e){return T(this._auth,e?_:m)}signInWithCustomToken(e){return R(this._auth,e)}signInWithEmailAndPassword(e,t){return k(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 x(this._auth)}updatePassword(e,t){if(!this.loggedUser)throw Error("Firebase: user is not logged!");let r=f.credential(this.loggedUser.email,e);return C(this.loggedUser,r).then(()=>y(this.loggedUser,t))}updateUserProfile(e){if(!this.loggedUser)throw Error("Firebase: user is not logged!");return M(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 U("apple.com"),[s.FACEBOOK]:new I().setCustomParameters({prompt:"select_account"}),[s.GOOGLE]:new P().setCustomParameters({prompt:"select_account"})})}async _expandDifferentCredential(e){if(e?.code===d.DIFFERENT_CREDENTIAL){let t=await this.fetchSignInMethodsForEmail(e.customData.email);throw e.code=d["DIFFERENT_CREDENTIAL_"+t[0]],e}}_generateAppId(){return`smp_firebase_client_${++a._instanceCounter}`}_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:o(()=>Promise.resolve(t.stsTokenManager.accessToken),"getIdToken")}}}catch(e){this._logger.debug("Firebase: error while getting stored user",e)}}_resolveApp(e){return u().some(t=>t.name===this._appId)?g(this._appId):p(e,this._appId)}_setTenant(e){this._auth.tenantId=e||null}async _signInWithProvider(e,t=this.socialLoginUXMode){return(t===n.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===d.POPUP_BLOCKED&&(this._logger.warn(`Firebase: social signin popup blocked (${++this._popupErrors}`),this._popupFallsBackToRedirect&&this._popupErrors>1)?(this._popupErrors=0,this._signInWithProvider(e,n.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)})}};var l=class a extends h{static{o(this,"SmpFirebaseService")}static get INSTANCE(){if(!(this._instance instanceof a))throw Error("SmpFirebaseService instance doesn't exist! Call SmpFirebaseService.init first!");return this._instance}static _instance;constructor(e,t){super(e,t)}static init(e,t){return this._instance||(this._instance=new a(e,t)),this._instance}};export{h as SmpFirebaseClient,d as SmpFirebaseErrors,l as SmpFirebaseService};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { S as SmpAbstractCacheStrategy, a as SmpCachedValue } from './smp-cached-value.interface-BdPg-J7L.js';
|
|
2
2
|
import { SmpLoggerMethods } from '@tonysamperi/logger';
|
|
3
3
|
export { smpNoop } from '@tonysamperi/logger';
|
|
4
|
-
import { S as SmpResponseMessage, a as SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-
|
|
5
|
-
export { c as SmpResponseMessageBase } from './smp-generic-response-base.interface-
|
|
4
|
+
import { S as SmpResponseMessage, a as SmpResponseMessageTypes, b as SmpGenericResponseBase } from './smp-generic-response-base.interface-BSdPo_xm.js';
|
|
5
|
+
export { c as SmpResponseMessageBase } from './smp-generic-response-base.interface-BSdPo_xm.js';
|
|
6
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';
|
|
@@ -111,6 +111,8 @@ declare enum SmpRestVerbs {
|
|
|
111
111
|
POST = "POST",
|
|
112
112
|
PUT = "PUT",
|
|
113
113
|
DELETE = "DELETE",
|
|
114
|
+
HEAD = "HEAD",
|
|
115
|
+
OPTIONS = "OPTIONS",
|
|
114
116
|
PATCH = "PATCH"
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -127,6 +129,8 @@ interface SmpHttpTwoConfig<T = any> {
|
|
|
127
129
|
queryParams?: Record<string, Exclude<SmpPrimitive, symbol> | Exclude<SmpPrimitive, symbol>[]>;
|
|
128
130
|
transform?: boolean;
|
|
129
131
|
responseType?: "blob" | "arraybuffer" | "text" | "json" | "jsonp";
|
|
132
|
+
/** Timeout in milliseconds after which the request will be aborted */
|
|
133
|
+
timeout?: number;
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
interface ParseableErrorClass<T> {
|
|
@@ -191,6 +195,7 @@ declare class SmpGenericResponse<T, U = SmpGenericResponseBase> implements SmpGe
|
|
|
191
195
|
constructor(_messages?: SmpResponseMessage[], data?: T | undefined);
|
|
192
196
|
static create<T = any>(config: Partial<SmpGenericResponseCreateOpts<T>>): SmpGenericResponse<T>;
|
|
193
197
|
static fromPlain(plain: unknown): SmpGenericResponse<any, SmpGenericResponseBase<any>>;
|
|
198
|
+
clone(): this;
|
|
194
199
|
isError(): boolean;
|
|
195
200
|
isSuccess(): boolean;
|
|
196
201
|
serialize(): U;
|
|
@@ -215,6 +220,13 @@ declare class SmpErrorResponse<T = any> extends SmpGenericResponse<T, SmpGeneric
|
|
|
215
220
|
static fromPlain(plain: unknown): SmpErrorResponse<any>;
|
|
216
221
|
}
|
|
217
222
|
|
|
223
|
+
declare class SmpErrorResponseWithStackTrace<T = any> extends SmpErrorResponse<T> {
|
|
224
|
+
stackTrace?: string;
|
|
225
|
+
static create<T>({ messages, stackTrace, ...opts }?: Partial<SmpErrorResponseCreateOpts<T>> & {
|
|
226
|
+
stackTrace?: string;
|
|
227
|
+
}): SmpErrorResponseWithStackTrace<T>;
|
|
228
|
+
}
|
|
229
|
+
|
|
218
230
|
declare const SMP_HEALTHZ: {
|
|
219
231
|
status: string;
|
|
220
232
|
};
|
|
@@ -726,6 +738,7 @@ declare class SmpCrypto {
|
|
|
726
738
|
static base64Decode(str: string): string;
|
|
727
739
|
static base64Encode(str: string): string;
|
|
728
740
|
static generateCorrelationId(): string;
|
|
741
|
+
static generateUuidV4(): string;
|
|
729
742
|
static md5(data: string): string;
|
|
730
743
|
static sha1(data: string): string;
|
|
731
744
|
static sha256(data: string): string;
|
|
@@ -938,7 +951,7 @@ declare class SmpCommonUtils {
|
|
|
938
951
|
static sprintf(str: string, ...argv: (string | number | symbol)[]): string;
|
|
939
952
|
static stripComments(html: string): string;
|
|
940
953
|
/**
|
|
941
|
-
* Strips all
|
|
954
|
+
* Strips all the html from string.
|
|
942
955
|
* @param html
|
|
943
956
|
* @param decodeEntities should decode entities? Default TRUE
|
|
944
957
|
*/
|
|
@@ -955,7 +968,6 @@ declare class SmpCommonUtils {
|
|
|
955
968
|
static toSnakeCase(s: string): string;
|
|
956
969
|
static toUpperSnakeCase(s: string): string;
|
|
957
970
|
static words(string: string, pattern?: RegExp): string[];
|
|
958
|
-
protected static _decodeHtmlEntities(value: string): string;
|
|
959
971
|
}
|
|
960
972
|
|
|
961
973
|
declare class SmpFilterException extends Error {
|
|
@@ -987,6 +999,7 @@ declare class SmpRegularExpressions {
|
|
|
987
999
|
static get LATIN_CHARS(): RegExp;
|
|
988
1000
|
static get LOCALE(): RegExp;
|
|
989
1001
|
static get NO_EMOJI_NO_PUNCTUATION(): RegExp;
|
|
1002
|
+
static get NO_HTML(): RegExp;
|
|
990
1003
|
static get PHONE_NUMBER(): RegExp;
|
|
991
1004
|
static get PHONE_NUMBER_BY_PREFIX(): Record<string, Record<string, RegExp>>;
|
|
992
1005
|
static get TAXCODE_BY_COUNTRY(): Record<string, Record<string, RegExp>>;
|
|
@@ -1013,6 +1026,6 @@ declare class SmpInMemoryCache extends SmpAbstractTtlCacheStrategy {
|
|
|
1013
1026
|
*/
|
|
1014
1027
|
declare function smpIsSmpCachedValue<T>(value: unknown): value is SmpCachedValue<T>;
|
|
1015
1028
|
|
|
1016
|
-
declare const VERSION: "2.
|
|
1029
|
+
declare const VERSION: "2.1.0";
|
|
1017
1030
|
|
|
1018
|
-
export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpAesCryptV2, 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 };
|
|
1031
|
+
export { SMP_HEALTHZ, SmpAbstractCacheStrategy, SmpAbstractTtlCacheStrategy, SmpAesCrypt, SmpAesCryptV2, SmpApiCommonUtils, SmpBaseJwtToken, SmpBaseJwtTokenPlain, SmpBrowserCache, SmpCachedValue, SmpCommonUtils, SmpCrypto, type SmpDynamicFetchReturn, SmpErrorResponse, type SmpErrorResponseCreateOpts, SmpErrorResponseWithStackTrace, 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 };
|