@blux.ai/web-sdk 0.0.7 → 1.0.0-rc0
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 +19 -19
- package/dist/package.json +35 -0
- package/package.json +2 -2
- package/demo/src/App.test.tsx +0 -9
- package/demo/src/App.tsx +0 -252
- package/demo/src/index.css +0 -16
- package/demo/src/index.tsx +0 -19
- package/demo/src/react-app-env.d.ts +0 -1
- package/demo/src/reportWebVitals.ts +0 -15
- package/demo/src/setupTests.ts +0 -5
- package/dist/BluxClient.d.ts +0 -43
- package/dist/BluxClient.js +0 -190
- package/dist/BluxClient.js.map +0 -1
- package/dist/apis/APIs.d.ts +0 -317
- package/dist/apis/APIs.js +0 -138
- package/dist/apis/APIs.js.map +0 -1
- package/dist/apis/createEvent.d.ts +0 -4
- package/dist/apis/createEvent.js +0 -7
- package/dist/apis/createEvent.js.map +0 -1
- package/dist/apis/getItemRecommendation.d.ts +0 -4
- package/dist/apis/getItemRecommendation.js +0 -7
- package/dist/apis/getItemRecommendation.js.map +0 -1
- package/dist/apis/initialize.d.ts +0 -4
- package/dist/apis/initialize.js +0 -7
- package/dist/apis/initialize.js.map +0 -1
- package/dist/apis/signIn.d.ts +0 -4
- package/dist/apis/signIn.js +0 -7
- package/dist/apis/signIn.js.map +0 -1
- package/dist/apis/signOut.d.ts +0 -4
- package/dist/apis/signOut.js +0 -7
- package/dist/apis/signOut.js.map +0 -1
- package/dist/apis/updateCustomUserProperties.d.ts +0 -4
- package/dist/apis/updateCustomUserProperties.js +0 -7
- package/dist/apis/updateCustomUserProperties.js.map +0 -1
- package/dist/apis/updateUserProperties.d.ts +0 -4
- package/dist/apis/updateUserProperties.js +0 -7
- package/dist/apis/updateUserProperties.js.map +0 -1
- package/dist/constants/COUNTRIES.d.ts +0 -928
- package/dist/constants/COUNTRIES.js +0 -1159
- package/dist/constants/COUNTRIES.js.map +0 -1
- package/dist/constants/ISO8601_REGEX.d.ts +0 -1
- package/dist/constants/ISO8601_REGEX.js +0 -4
- package/dist/constants/ISO8601_REGEX.js.map +0 -1
- package/dist/constants/URLS.d.ts +0 -6
- package/dist/constants/URLS.js +0 -7
- package/dist/constants/URLS.js.map +0 -1
- package/dist/events/AddCartaddEvent.d.ts +0 -5
- package/dist/events/AddCartaddEvent.js +0 -11
- package/dist/events/AddCartaddEvent.js.map +0 -1
- package/dist/events/AddCustomEvent.d.ts +0 -5
- package/dist/events/AddCustomEvent.js +0 -12
- package/dist/events/AddCustomEvent.js.map +0 -1
- package/dist/events/AddLikeEvent.d.ts +0 -5
- package/dist/events/AddLikeEvent.js +0 -11
- package/dist/events/AddLikeEvent.js.map +0 -1
- package/dist/events/AddPageViewEvent.d.ts +0 -5
- package/dist/events/AddPageViewEvent.js +0 -11
- package/dist/events/AddPageViewEvent.js.map +0 -1
- package/dist/events/AddProductDetailViewEvent.d.ts +0 -5
- package/dist/events/AddProductDetailViewEvent.js +0 -11
- package/dist/events/AddProductDetailViewEvent.js.map +0 -1
- package/dist/events/AddPurchaseEvent.d.ts +0 -5
- package/dist/events/AddPurchaseEvent.js +0 -12
- package/dist/events/AddPurchaseEvent.js.map +0 -1
- package/dist/events/AddRateEvent.d.ts +0 -5
- package/dist/events/AddRateEvent.js +0 -12
- package/dist/events/AddRateEvent.js.map +0 -1
- package/dist/events/AddRecommendationViewEvent.d.ts +0 -5
- package/dist/events/AddRecommendationViewEvent.js +0 -10
- package/dist/events/AddRecommendationViewEvent.js.map +0 -1
- package/dist/events/Event.d.ts +0 -16
- package/dist/events/Event.js +0 -24
- package/dist/events/Event.js.map +0 -1
- package/dist/events/VisitEvent.d.ts +0 -5
- package/dist/events/VisitEvent.js +0 -10
- package/dist/events/VisitEvent.js.map +0 -1
- package/dist/events/index.d.ts +0 -8
- package/dist/events/index.js +0 -9
- package/dist/events/index.js.map +0 -1
- package/dist/events/types.d.ts +0 -38
- package/dist/events/types.js +0 -2
- package/dist/events/types.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/recommendations/ItemRecommendation.d.ts +0 -5
- package/dist/recommendations/ItemRecommendation.js +0 -12
- package/dist/recommendations/ItemRecommendation.js.map +0 -1
- package/dist/recommendations/Recommendation.d.ts +0 -5
- package/dist/recommendations/Recommendation.js +0 -9
- package/dist/recommendations/Recommendation.js.map +0 -1
- package/dist/recommendations/index.d.ts +0 -1
- package/dist/recommendations/index.js +0 -2
- package/dist/recommendations/index.js.map +0 -1
- package/dist/recommendations/types.d.ts +0 -11
- package/dist/recommendations/types.js +0 -2
- package/dist/recommendations/types.js.map +0 -1
- package/dist/utils/Base.d.ts +0 -13
- package/dist/utils/Base.js +0 -2
- package/dist/utils/Base.js.map +0 -1
- package/dist/utils/LocalStorage.d.ts +0 -4
- package/dist/utils/LocalStorage.js +0 -14
- package/dist/utils/LocalStorage.js.map +0 -1
- package/dist/utils/Logger.d.ts +0 -13
- package/dist/utils/Logger.js +0 -49
- package/dist/utils/Logger.js.map +0 -1
- package/dist/utils/assertEqualTypes.d.ts +0 -3
- package/dist/utils/assertEqualTypes.js +0 -5
- package/dist/utils/assertEqualTypes.js.map +0 -1
- package/dist/utils/getPath.d.ts +0 -1
- package/dist/utils/getPath.js +0 -9
- package/dist/utils/getPath.js.map +0 -1
- package/dist/utils/helper.d.ts +0 -1
- package/dist/utils/helper.js +0 -4
- package/dist/utils/helper.js.map +0 -1
- package/dist/utils/operators.d.ts +0 -2
- package/dist/utils/operators.js +0 -6
- package/dist/utils/operators.js.map +0 -1
- package/dist/utils/zodSchemas.d.ts +0 -19
- package/dist/utils/zodSchemas.js +0 -105
- package/dist/utils/zodSchemas.js.map +0 -1
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const BLUX_DEVICE_ID = "blux_deviceId";
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
3
|
-
export class LocalStorage {
|
|
4
|
-
static getDeviceId() {
|
|
5
|
-
const deviceId = localStorage.getItem(BLUX_DEVICE_ID);
|
|
6
|
-
return deviceId === "undefined" || deviceId?.trim() === ""
|
|
7
|
-
? null
|
|
8
|
-
: deviceId;
|
|
9
|
-
}
|
|
10
|
-
static setDeviceId(deviceId) {
|
|
11
|
-
localStorage.setItem(BLUX_DEVICE_ID, deviceId);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=LocalStorage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalStorage.js","sourceRoot":"/","sources":["utils/LocalStorage.ts"],"names":[],"mappings":"AAAA,MAAM,cAAc,GAAG,eAAe,CAAC;AAEvC,kEAAkE;AAClE,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,WAAW;QAChB,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACtD,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE;YACxD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,QAAgB;QACjC,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["const BLUX_DEVICE_ID = \"blux_deviceId\";\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class LocalStorage {\n static getDeviceId(): string | null {\n const deviceId = localStorage.getItem(BLUX_DEVICE_ID);\n return deviceId === \"undefined\" || deviceId?.trim() === \"\"\n ? null\n : deviceId;\n }\n\n static setDeviceId(deviceId: string) {\n localStorage.setItem(BLUX_DEVICE_ID, deviceId);\n }\n}\n"]}
|
package/dist/utils/Logger.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ScopeContext } from "@sentry/types";
|
|
2
|
-
export type LogLevel = "debug" | "log" | "warning" | "error" | "fatal";
|
|
3
|
-
export type Context = Partial<Pick<ScopeContext, "tags" | "extra">>;
|
|
4
|
-
export declare class Logger {
|
|
5
|
-
static logLevel: LogLevel;
|
|
6
|
-
private static base;
|
|
7
|
-
static debug(message: string | Error, context?: Context): void;
|
|
8
|
-
static log(message: string | Error, context?: Context): void;
|
|
9
|
-
static warning(message: string | Error, context?: Context): void;
|
|
10
|
-
static error(message: string | Error, context?: Context): void;
|
|
11
|
-
static fatal(message: string | Error, context?: Context): void;
|
|
12
|
-
static setLevel(level: LogLevel): void;
|
|
13
|
-
}
|
package/dist/utils/Logger.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const consoleMethodByLevel = {
|
|
2
|
-
debug: console.debug.bind(console),
|
|
3
|
-
log: console.log.bind(console),
|
|
4
|
-
warning: console.warn.bind(console),
|
|
5
|
-
error: console.error.bind(console),
|
|
6
|
-
fatal: console.error.bind(console),
|
|
7
|
-
};
|
|
8
|
-
const LOG_LEVEL_ORDERS = {
|
|
9
|
-
debug: 0,
|
|
10
|
-
log: 1,
|
|
11
|
-
warning: 2,
|
|
12
|
-
error: 3,
|
|
13
|
-
fatal: 4,
|
|
14
|
-
};
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
16
|
-
export class Logger {
|
|
17
|
-
static logLevel = "error";
|
|
18
|
-
static base(message, level, context) {
|
|
19
|
-
if (LOG_LEVEL_ORDERS[level] >= LOG_LEVEL_ORDERS[this.logLevel]) {
|
|
20
|
-
const logForConsole = ["[BluxClient]", message];
|
|
21
|
-
if (context?.extra) {
|
|
22
|
-
logForConsole.push(context.extra);
|
|
23
|
-
}
|
|
24
|
-
if (context?.tags) {
|
|
25
|
-
logForConsole.push(context.tags);
|
|
26
|
-
}
|
|
27
|
-
consoleMethodByLevel[level]?.(...logForConsole);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
static debug(message, context) {
|
|
31
|
-
this.base(message, "debug", context);
|
|
32
|
-
}
|
|
33
|
-
static log(message, context) {
|
|
34
|
-
this.base(message, "log", context);
|
|
35
|
-
}
|
|
36
|
-
static warning(message, context) {
|
|
37
|
-
this.base(message, "warning", context);
|
|
38
|
-
}
|
|
39
|
-
static error(message, context) {
|
|
40
|
-
this.base(message, "error", context);
|
|
41
|
-
}
|
|
42
|
-
static fatal(message, context) {
|
|
43
|
-
this.base(message, "fatal", context);
|
|
44
|
-
}
|
|
45
|
-
static setLevel(level) {
|
|
46
|
-
this.logLevel = level;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=Logger.js.map
|
package/dist/utils/Logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"/","sources":["utils/Logger.ts"],"names":[],"mappings":"AAGA,MAAM,oBAAoB,GAAG;IAC3B,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;IAClC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;CAC1B,CAAC;AAIX,MAAM,gBAAgB,GAAG;IACvB,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,CAAC;IACN,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;CACT,CAAC;AAIF,kEAAkE;AAClE,MAAM,OAAO,MAAM;IACV,MAAM,CAAC,QAAQ,GAAa,OAAO,CAAC;IAEnC,MAAM,CAAC,IAAI,CACjB,OAAuB,EACvB,KAAe,EACf,OAAiB;QAEjB,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC9D,MAAM,aAAa,GAAc,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YAE3D,IAAI,OAAO,EAAE,KAAK,EAAE;gBAClB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;aACnC;YACD,IAAI,OAAO,EAAE,IAAI,EAAE;gBACjB,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAClC;YAED,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC;SACjD;IACH,CAAC;IACM,MAAM,CAAC,KAAK,CAAC,OAAuB,EAAE,OAAiB;QAC5D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACM,MAAM,CAAC,GAAG,CAAC,OAAuB,EAAE,OAAiB;QAC1D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;IACM,MAAM,CAAC,OAAO,CAAC,OAAuB,EAAE,OAAiB;QAC9D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACM,MAAM,CAAC,KAAK,CAAC,OAAuB,EAAE,OAAiB;QAC5D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACM,MAAM,CAAC,KAAK,CAAC,OAAuB,EAAE,OAAiB;QAC5D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAEM,MAAM,CAAC,QAAQ,CAAC,KAAe;QACpC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC","sourcesContent":["/* eslint-disable no-console */\nimport type { ScopeContext } from \"@sentry/types\";\n\nconst consoleMethodByLevel = {\n debug: console.debug.bind(console),\n log: console.log.bind(console),\n warning: console.warn.bind(console),\n error: console.error.bind(console),\n fatal: console.error.bind(console),\n} as const;\n\nexport type LogLevel = \"debug\" | \"log\" | \"warning\" | \"error\" | \"fatal\";\n\nconst LOG_LEVEL_ORDERS = {\n debug: 0,\n log: 1,\n warning: 2,\n error: 3,\n fatal: 4,\n};\n\nexport type Context = Partial<Pick<ScopeContext, \"tags\" | \"extra\">>;\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class Logger {\n public static logLevel: LogLevel = \"error\";\n\n private static base(\n message: string | Error,\n level: LogLevel,\n context?: Context,\n ) {\n if (LOG_LEVEL_ORDERS[level] >= LOG_LEVEL_ORDERS[this.logLevel]) {\n const logForConsole: unknown[] = [\"[BluxClient]\", message];\n\n if (context?.extra) {\n logForConsole.push(context.extra);\n }\n if (context?.tags) {\n logForConsole.push(context.tags);\n }\n\n consoleMethodByLevel[level]?.(...logForConsole);\n }\n }\n public static debug(message: string | Error, context?: Context) {\n this.base(message, \"debug\", context);\n }\n public static log(message: string | Error, context?: Context) {\n this.base(message, \"log\", context);\n }\n public static warning(message: string | Error, context?: Context) {\n this.base(message, \"warning\", context);\n }\n public static error(message: string | Error, context?: Context) {\n this.base(message, \"error\", context);\n }\n public static fatal(message: string | Error, context?: Context) {\n this.base(message, \"fatal\", context);\n }\n\n public static setLevel(level: LogLevel) {\n this.logLevel = level;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertEqualTypes.js","sourceRoot":"/","sources":["utils/assertEqualTypes.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAO,IAAuB;IAC5D,aAAa;AACf,CAAC;AAKD,gBAAgB,CAAe,IAAI,CAAC,CAAC","sourcesContent":["type AssertEqual<T, U> = T extends U ? (U extends T ? true : never) : never;\n\nexport function assertEqualTypes<T, U>(_arg: AssertEqual<T, U>): void {\n // do nothing\n}\n\n// exmaples\ntype TypeA = { name: string; age: number };\ntype TypeB = { name: string; age: number };\nassertEqualTypes<TypeA, TypeB>(true);\n"]}
|
package/dist/utils/getPath.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getPath(path: string, pathParams: Record<string, string>): string;
|
package/dist/utils/getPath.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export function getPath(path, pathParams) {
|
|
2
|
-
return Object.keys(pathParams).reduce((acc, key) => {
|
|
3
|
-
const value = pathParams[key];
|
|
4
|
-
if (value === undefined)
|
|
5
|
-
return acc;
|
|
6
|
-
return acc.replace(new RegExp(`\\{${key}\\}`, "g"), value);
|
|
7
|
-
}, path);
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=getPath.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPath.js","sourceRoot":"/","sources":["utils/getPath.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,UAAkC;IACtE,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACjD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC;QAEpC,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC,EAAE,IAAI,CAAC,CAAC;AACX,CAAC","sourcesContent":["export function getPath(path: string, pathParams: Record<string, string>) {\n return Object.keys(pathParams).reduce((acc, key) => {\n const value = pathParams[key];\n if (value === undefined) return acc;\n\n return acc.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), value);\n }, path);\n}\n"]}
|
package/dist/utils/helper.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getCurrentUnixTimestamp: () => number;
|
package/dist/utils/helper.js
DELETED
package/dist/utils/helper.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"/","sources":["utils/helper.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,OAAO,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC;AACpC,CAAC,CAAC","sourcesContent":["export const getCurrentUnixTimestamp = () => {\n return new Date().getTime() / 1e3;\n};\n"]}
|
package/dist/utils/operators.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operators.js","sourceRoot":"/","sources":["utils/operators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,MAAM,UAAU,cAAc;IAC5B,6CAA6C;IAC7C,OAAO,MAAM,CAAC,CAAC,CAAC,EAAU,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import type { OperatorFunction } from \"rxjs\";\nimport { filter } from \"rxjs\";\n\nexport function filterNullable<T>(): OperatorFunction<T | null | undefined, T> {\n // eslint-disable-next-line no-eq-null,eqeqeq\n return filter((v): v is T => v != null);\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import ObjectId from "bson-objectid";
|
|
3
|
-
export declare const objectIdSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, ObjectId, string>;
|
|
4
|
-
export declare const stringToNumberSchema: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber]>, string | number, string | number>, number, string | number>;
|
|
5
|
-
export declare const dateSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>;
|
|
6
|
-
export declare const anonymousObjectSchema: <T extends object = object>() => z.ZodEffects<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, T, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
|
|
7
|
-
export declare const countryCodeWithLowerCaseSchema: z.ZodEffects<z.ZodEnum<["AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AI" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BM" | "BT" | "BO" | "BA" | "BW" | "BR" | "IO" | "BN" | "BG" | "BF" | "BI" | "KH" | "CM" | "CV" | "KY" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CG" | "CD" | "CK" | "CR" | "CI" | "HR" | "CU" | "CY" | "CZ" | "DK" | "DJ" | "DM" | "DO" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FK" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GI" | "GR" | "GL" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "HT" | "VA" | "HN" | "HK" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IL" | "IT" | "JM" | "JP" | "JO" | "KE" | "KI" | "KP" | "KR" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LY" | "LI" | "LT" | "LU" | "MO" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MH" | "MQ" | "MR" | "MU" | "YT" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "MM" | "NA" | "NR" | "NP" | "NL" | "NC" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "MP" | "NO" | "OM" | "PK" | "PW" | "PS" | "PA" | "PG" | "PY" | "GY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "RO" | "RU" | "KZ" | "RW" | "RE" | "BL" | "SH" | "KN" | "LC" | "MF" | "PM" | "VC" | "WS" | "SM" | "ST" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SK" | "SI" | "SB" | "SO" | "ZA" | "SS" | "ES" | "LK" | "SD" | "SR" | "SZ" | "SE" | "CH" | "SY" | "TW" | "TJ" | "TZ" | "TH" | "TL" | "TG" | "TK" | "TO" | "TT" | "TN" | "TR" | "TM" | "TC" | "TV" | "UG" | "UA" | "AE" | "GB" | "US" | "CA" | "UY" | "UZ" | "VU" | "VE" | "VN" | "VG" | "VI" | "WF" | "YE" | "ZM" | "ZW", ...("AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AI" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BM" | "BT" | "BO" | "BA" | "BW" | "BR" | "IO" | "BN" | "BG" | "BF" | "BI" | "KH" | "CM" | "CV" | "KY" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CG" | "CD" | "CK" | "CR" | "CI" | "HR" | "CU" | "CY" | "CZ" | "DK" | "DJ" | "DM" | "DO" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FK" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GI" | "GR" | "GL" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "HT" | "VA" | "HN" | "HK" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IL" | "IT" | "JM" | "JP" | "JO" | "KE" | "KI" | "KP" | "KR" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LY" | "LI" | "LT" | "LU" | "MO" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MH" | "MQ" | "MR" | "MU" | "YT" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "MM" | "NA" | "NR" | "NP" | "NL" | "NC" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "MP" | "NO" | "OM" | "PK" | "PW" | "PS" | "PA" | "PG" | "PY" | "GY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "RO" | "RU" | "KZ" | "RW" | "RE" | "BL" | "SH" | "KN" | "LC" | "MF" | "PM" | "VC" | "WS" | "SM" | "ST" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SK" | "SI" | "SB" | "SO" | "ZA" | "SS" | "ES" | "LK" | "SD" | "SR" | "SZ" | "SE" | "CH" | "SY" | "TW" | "TJ" | "TZ" | "TH" | "TL" | "TG" | "TK" | "TO" | "TT" | "TN" | "TR" | "TM" | "TC" | "TV" | "UG" | "UA" | "AE" | "GB" | "US" | "CA" | "UY" | "UZ" | "VU" | "VE" | "VN" | "VG" | "VI" | "WF" | "YE" | "ZM" | "ZW")[]]>, "AF" | "AL" | "DZ" | "AS" | "AD" | "AO" | "AI" | "AG" | "AR" | "AM" | "AW" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BM" | "BT" | "BO" | "BA" | "BW" | "BR" | "IO" | "BN" | "BG" | "BF" | "BI" | "KH" | "CM" | "CV" | "KY" | "CF" | "TD" | "CL" | "CN" | "CO" | "KM" | "CG" | "CD" | "CK" | "CR" | "CI" | "HR" | "CU" | "CY" | "CZ" | "DK" | "DJ" | "DM" | "DO" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "ET" | "FK" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GI" | "GR" | "GL" | "GD" | "GP" | "GU" | "GT" | "GN" | "GW" | "HT" | "VA" | "HN" | "HK" | "HU" | "IS" | "IN" | "ID" | "IR" | "IQ" | "IE" | "IL" | "IT" | "JM" | "JP" | "JO" | "KE" | "KI" | "KP" | "KR" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LY" | "LI" | "LT" | "LU" | "MO" | "MK" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MH" | "MQ" | "MR" | "MU" | "YT" | "MX" | "FM" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "MM" | "NA" | "NR" | "NP" | "NL" | "NC" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "MP" | "NO" | "OM" | "PK" | "PW" | "PS" | "PA" | "PG" | "PY" | "GY" | "PE" | "PH" | "PL" | "PT" | "PR" | "QA" | "RO" | "RU" | "KZ" | "RW" | "RE" | "BL" | "SH" | "KN" | "LC" | "MF" | "PM" | "VC" | "WS" | "SM" | "ST" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SK" | "SI" | "SB" | "SO" | "ZA" | "SS" | "ES" | "LK" | "SD" | "SR" | "SZ" | "SE" | "CH" | "SY" | "TW" | "TJ" | "TZ" | "TH" | "TL" | "TG" | "TK" | "TO" | "TT" | "TN" | "TR" | "TM" | "TC" | "TV" | "UG" | "UA" | "AE" | "GB" | "US" | "CA" | "UY" | "UZ" | "VU" | "VE" | "VN" | "VG" | "VI" | "WF" | "YE" | "ZM" | "ZW", unknown>;
|
|
8
|
-
export declare const customPropertiesRequestSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodNull]>>;
|
|
9
|
-
export declare const customPropertiesSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">]>>;
|
|
10
|
-
export type CustomProperties = z.infer<typeof customPropertiesSchema>;
|
|
11
|
-
export declare enum CustomPropertyDataType {
|
|
12
|
-
DATE = "DATE",
|
|
13
|
-
STRING = "STRING",
|
|
14
|
-
NUMBER = "NUMBER",
|
|
15
|
-
BOOLEAN = "BOOLEAN",
|
|
16
|
-
ARRAY_OF_STRING = "ARRAY_OF_STRING"
|
|
17
|
-
}
|
|
18
|
-
export declare const stringToObjectIdsSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string[], string>, string[], string>, ObjectId[], string>;
|
|
19
|
-
export declare const stringToArraySchema: z.ZodEffects<z.ZodEffects<z.ZodString, string[], string>, string[], string>;
|
package/dist/utils/zodSchemas.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { z, ZodError } from "zod";
|
|
2
|
-
import { COUNTRY_CODES } from "../constants/COUNTRIES";
|
|
3
|
-
import { assertEqualTypes } from "./assertEqualTypes";
|
|
4
|
-
import { ISO8601_REGEX } from "../constants/ISO8601_REGEX";
|
|
5
|
-
import ObjectId from "bson-objectid";
|
|
6
|
-
function isObjectId(value) {
|
|
7
|
-
return (typeof value === "string" && value.length === 24 && ObjectId.isValid(value));
|
|
8
|
-
}
|
|
9
|
-
export const objectIdSchema = z
|
|
10
|
-
.string()
|
|
11
|
-
.refine((v) => isObjectId(v), (v) => new ZodError([
|
|
12
|
-
{
|
|
13
|
-
code: "custom",
|
|
14
|
-
message: `Invalid ObjectId: ${v}`,
|
|
15
|
-
path: ["some_path"],
|
|
16
|
-
},
|
|
17
|
-
]))
|
|
18
|
-
.transform((v) => new ObjectId(v));
|
|
19
|
-
export const stringToNumberSchema = z
|
|
20
|
-
.union([z.string(), z.number()])
|
|
21
|
-
.refine((v) => {
|
|
22
|
-
if (typeof v === "number")
|
|
23
|
-
return true;
|
|
24
|
-
const parsed = Number(v);
|
|
25
|
-
return !isNaN(parsed);
|
|
26
|
-
}, {
|
|
27
|
-
message: "Invalid number or string in stringToNumberSchema",
|
|
28
|
-
})
|
|
29
|
-
.transform((v) => (typeof v === "number" ? v : Number(v)));
|
|
30
|
-
export const dateSchema = z
|
|
31
|
-
.string()
|
|
32
|
-
.refine((dateString) => {
|
|
33
|
-
return ISO8601_REGEX.test(dateString);
|
|
34
|
-
}, {
|
|
35
|
-
message: "Invalid date string",
|
|
36
|
-
})
|
|
37
|
-
.transform((dateString) => new Date(dateString));
|
|
38
|
-
function convertAllObjectId(input) {
|
|
39
|
-
if (Array.isArray(input)) {
|
|
40
|
-
return input.map((item) => convertAllObjectId(item));
|
|
41
|
-
}
|
|
42
|
-
else if (isObjectId(input)) {
|
|
43
|
-
return new ObjectId(input);
|
|
44
|
-
}
|
|
45
|
-
else if (typeof input === "string" &&
|
|
46
|
-
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/.test(input)) {
|
|
47
|
-
return new Date(input);
|
|
48
|
-
}
|
|
49
|
-
else if (input !== null && typeof input === "object") {
|
|
50
|
-
return Object.entries(input).reduce((acc, [key, value]) => {
|
|
51
|
-
acc[key] = convertAllObjectId(value);
|
|
52
|
-
return acc;
|
|
53
|
-
}, {});
|
|
54
|
-
}
|
|
55
|
-
return input;
|
|
56
|
-
}
|
|
57
|
-
export const anonymousObjectSchema = () => z
|
|
58
|
-
.object({})
|
|
59
|
-
.passthrough()
|
|
60
|
-
.transform((v) => convertAllObjectId(v));
|
|
61
|
-
export const countryCodeWithLowerCaseSchema = z.preprocess((v) => {
|
|
62
|
-
if (v === "419")
|
|
63
|
-
return undefined; // https://en.wikipedia.org/wiki/Language_code
|
|
64
|
-
if (typeof v === "string")
|
|
65
|
-
return v.toUpperCase();
|
|
66
|
-
return v;
|
|
67
|
-
}, z.enum(COUNTRY_CODES));
|
|
68
|
-
export const customPropertiesRequestSchema = z.record(z.union([
|
|
69
|
-
dateSchema,
|
|
70
|
-
z.string(),
|
|
71
|
-
z.number(),
|
|
72
|
-
z.boolean(),
|
|
73
|
-
z.array(z.string()),
|
|
74
|
-
z.null(),
|
|
75
|
-
]));
|
|
76
|
-
export const customPropertiesSchema = z.record(z.union([
|
|
77
|
-
dateSchema,
|
|
78
|
-
z.string(),
|
|
79
|
-
z.number(),
|
|
80
|
-
z.boolean(),
|
|
81
|
-
z.array(z.string()),
|
|
82
|
-
]));
|
|
83
|
-
assertEqualTypes(true);
|
|
84
|
-
export var CustomPropertyDataType;
|
|
85
|
-
(function (CustomPropertyDataType) {
|
|
86
|
-
CustomPropertyDataType["DATE"] = "DATE";
|
|
87
|
-
CustomPropertyDataType["STRING"] = "STRING";
|
|
88
|
-
CustomPropertyDataType["NUMBER"] = "NUMBER";
|
|
89
|
-
CustomPropertyDataType["BOOLEAN"] = "BOOLEAN";
|
|
90
|
-
CustomPropertyDataType["ARRAY_OF_STRING"] = "ARRAY_OF_STRING";
|
|
91
|
-
})(CustomPropertyDataType || (CustomPropertyDataType = {}));
|
|
92
|
-
export const stringToObjectIdsSchema = z
|
|
93
|
-
.string()
|
|
94
|
-
.transform((v) => v.split(","))
|
|
95
|
-
.refine((arr) => arr.every((item) => item.length > 0), {
|
|
96
|
-
message: "Each ObjectId should not be empty",
|
|
97
|
-
})
|
|
98
|
-
.transform((arr) => arr.map((id) => objectIdSchema.parse(id)));
|
|
99
|
-
export const stringToArraySchema = z
|
|
100
|
-
.string()
|
|
101
|
-
.transform((v) => v.split(",").map((item) => item.trim()))
|
|
102
|
-
.refine((arr) => arr.every((item) => item.length > 0), {
|
|
103
|
-
message: "Each item should not be empty",
|
|
104
|
-
});
|
|
105
|
-
//# sourceMappingURL=zodSchemas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zodSchemas.js","sourceRoot":"/","sources":["utils/zodSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ,IAA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AI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;IACrD,OAAO,EAAE,mCAAmC;CAC7C,CAAC;KACD,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,EAAE;KACR,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;KACzD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;IACrD,OAAO,EAAE,+BAA+B;CACzC,CAAC,CAAC","sourcesContent":["import { z, ZodError } from \"zod\";\nimport type { CountryCode } from \"../constants/COUNTRIES\";\nimport { COUNTRY_CODES } from \"../constants/COUNTRIES\";\nimport { assertEqualTypes } from \"./assertEqualTypes\";\nimport { ISO8601_REGEX } from \"../constants/ISO8601_REGEX\";\nimport ObjectId from \"bson-objectid\";\n\nfunction isObjectId(value: unknown): value is string {\n return (\n typeof value === \"string\" && value.length === 24 && ObjectId.isValid(value)\n );\n}\n\nexport const objectIdSchema = z\n .string()\n .refine(\n (v) => isObjectId(v),\n (v) =>\n new ZodError([\n {\n code: \"custom\",\n message: `Invalid ObjectId: ${v}`,\n path: [\"some_path\"],\n },\n ]),\n )\n .transform((v) => new ObjectId(v));\n\nexport const stringToNumberSchema = z\n .union([z.string(), z.number()])\n .refine(\n (v) => {\n if (typeof v === \"number\") return true;\n const parsed = Number(v);\n return !isNaN(parsed);\n },\n {\n message: \"Invalid number or string in stringToNumberSchema\",\n },\n )\n .transform((v): number => (typeof v === \"number\" ? v : Number(v)));\n\nexport const dateSchema = z\n .string()\n .refine(\n (dateString) => {\n return ISO8601_REGEX.test(dateString);\n },\n {\n message: \"Invalid date string\",\n },\n )\n .transform((dateString) => new Date(dateString));\n\nfunction convertAllObjectId(input: unknown): unknown {\n if (Array.isArray(input)) {\n return input.map((item) => convertAllObjectId(item));\n } else if (isObjectId(input)) {\n return new ObjectId(input);\n } else if (\n typeof input === \"string\" &&\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/.test(input)\n ) {\n return new Date(input);\n } else if (input !== null && typeof input === \"object\") {\n return Object.entries(input).reduce<Record<string, unknown>>(\n (acc, [key, value]) => {\n acc[key] = convertAllObjectId(value);\n return acc;\n },\n {},\n );\n }\n return input;\n}\n\nexport const anonymousObjectSchema = <T extends object = object>() =>\n z\n .object({})\n .passthrough()\n .transform((v) => convertAllObjectId(v) as T);\n\nexport const countryCodeWithLowerCaseSchema = z.preprocess(\n (v) => {\n if (v === \"419\") return undefined; // https://en.wikipedia.org/wiki/Language_code\n if (typeof v === \"string\") return v.toUpperCase();\n return v;\n },\n z.enum(COUNTRY_CODES as [CountryCode, ...CountryCode[]]),\n);\n\nexport const customPropertiesRequestSchema = z.record(\n z.union([\n dateSchema,\n z.string(),\n z.number(),\n z.boolean(),\n z.array(z.string()),\n z.null(),\n ]),\n);\n\ntype CustomPropertiesRequest = z.infer<typeof customPropertiesRequestSchema>;\n\nexport const customPropertiesSchema = z.record(\n z.union([\n dateSchema,\n z.string(),\n z.number(),\n z.boolean(),\n z.array(z.string()),\n ]),\n);\n\nexport type CustomProperties = z.infer<typeof customPropertiesSchema>;\n\nassertEqualTypes<\n {\n [K in keyof CustomPropertiesRequest]: Exclude<\n CustomPropertiesRequest[K],\n null\n >;\n },\n CustomProperties\n>(true);\n\nexport enum CustomPropertyDataType {\n DATE = \"DATE\",\n STRING = \"STRING\",\n NUMBER = \"NUMBER\",\n BOOLEAN = \"BOOLEAN\",\n ARRAY_OF_STRING = \"ARRAY_OF_STRING\",\n}\n\nexport const stringToObjectIdsSchema = z\n .string()\n .transform((v) => v.split(\",\"))\n .refine((arr) => arr.every((item) => item.length > 0), {\n message: \"Each ObjectId should not be empty\",\n })\n .transform((arr) => arr.map((id) => objectIdSchema.parse(id)));\n\nexport const stringToArraySchema = z\n .string()\n .transform((v) => v.split(\",\").map((item) => item.trim()))\n .refine((arr) => arr.every((item) => item.length > 0), {\n message: \"Each item should not be empty\",\n });\n"]}
|