@rxdrag/website-lib-core 0.0.50 → 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/package.json +10 -9
  2. package/src/astro/README.md +1 -0
  3. package/src/astro/animation.ts +146 -0
  4. package/src/astro/background.ts +53 -0
  5. package/src/astro/grid/consts.ts +80 -0
  6. package/src/astro/grid/index.ts +2 -0
  7. package/src/astro/grid/types.ts +35 -0
  8. package/src/astro/index.ts +7 -0
  9. package/src/astro/media.ts +109 -0
  10. package/src/astro/section/index.ts +12 -0
  11. package/src/entify/Entify.ts +32 -2
  12. package/src/entify/IEntify.ts +30 -6
  13. package/src/entify/lib/createUploadCredentials.ts +56 -0
  14. package/src/entify/lib/index.ts +30 -29
  15. package/src/entify/lib/newQueryProductOptions.ts +1 -0
  16. package/src/entify/lib/queryLangs.ts +5 -5
  17. package/src/entify/lib/queryOneTheme.ts +12 -12
  18. package/src/index.ts +1 -0
  19. package/src/react/components/Analytics/eventHandlers.ts +173 -0
  20. package/src/react/components/Analytics/index.tsx +21 -0
  21. package/src/react/components/Analytics/singleton.ts +214 -0
  22. package/src/react/components/Analytics/tracking.ts +221 -0
  23. package/src/react/components/Analytics/types.ts +60 -0
  24. package/src/react/components/Analytics/utils.ts +95 -0
  25. package/src/react/components/BackgroundHlsVideoPlayer.tsx +68 -0
  26. package/src/react/components/BackgroundVideoPlayer.tsx +32 -0
  27. package/src/react/components/ContactForm/ContactForm.tsx +286 -0
  28. package/src/react/components/ContactForm/FileUpload.tsx +430 -0
  29. package/src/react/components/ContactForm/Input.tsx +6 -10
  30. package/src/react/components/ContactForm/Input2.tsx +64 -0
  31. package/src/react/components/ContactForm/Submit.tsx +25 -10
  32. package/src/react/components/ContactForm/Textarea.tsx +7 -10
  33. package/src/react/components/ContactForm/Textarea2.tsx +64 -0
  34. package/src/react/components/ContactForm/factory.tsx +49 -0
  35. package/src/react/components/ContactForm/funcs.ts +64 -0
  36. package/src/react/components/ContactForm/index.ts +7 -0
  37. package/src/react/components/ContactForm/types.ts +67 -0
  38. package/src/react/components/ContactForm/useVisitorInfo.ts +31 -0
  39. package/src/react/components/index.ts +3 -0
  40. package/src/react/components/ContactForm/index.tsx +0 -351
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdrag/website-lib-core",
3
- "version": "0.0.50",
3
+ "version": "0.0.51",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts"
@@ -20,22 +20,23 @@
20
20
  "@iconify/react": "^5.0.2",
21
21
  "@types/gsap": "^3.0.0",
22
22
  "@types/lodash-es": "^4.14.191",
23
- "@types/react": "^18.2.22",
24
- "@types/react-dom": "^18.2.7",
23
+ "@types/react": "^19.1.0",
24
+ "@types/react-dom": "^19.1.0",
25
25
  "eslint": "^7.32.0",
26
26
  "typescript": "^5",
27
- "@rxdrag/eslint-config-custom": "0.2.12",
28
27
  "@rxdrag/tsconfig": "0.2.0",
29
- "@rxdrag/slate-preview": "1.2.57"
28
+ "@rxdrag/eslint-config-custom": "0.2.12",
29
+ "@rxdrag/slate-preview": "1.2.58"
30
30
  },
31
31
  "dependencies": {
32
32
  "clsx": "^2.1.0",
33
33
  "gsap": "^3.12.7",
34
+ "hls.js": "^1.6.13",
34
35
  "lodash-es": "^4.17.21",
35
- "react": "^18.2.0",
36
- "react-dom": "^18.2.0",
37
- "@rxdrag/rxcms-models": "0.3.76",
38
- "@rxdrag/entify-lib": "0.0.8"
36
+ "react": "^19.1.0",
37
+ "react-dom": "^19.1.0",
38
+ "@rxdrag/rxcms-models": "0.3.77",
39
+ "@rxdrag/entify-lib": "0.0.9"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "astro": "^4.0.0 || ^5.0.0"
@@ -0,0 +1 @@
1
+ 定义astro物料用的一些接口
@@ -0,0 +1,146 @@
1
+ /**
2
+ * AOS (Animate On Scroll) 动画配置类型定义
3
+ * 基于 AOS 库的 data-aos 属性
4
+ */
5
+
6
+ // AOS 动画类型
7
+ export type AOSAnimation =
8
+ | "" // 无动效
9
+ // Fade animations
10
+ | "fade"
11
+ | "fade-up"
12
+ | "fade-down"
13
+ | "fade-left"
14
+ | "fade-right"
15
+ | "fade-up-right"
16
+ | "fade-up-left"
17
+ | "fade-down-right"
18
+ | "fade-down-left"
19
+ // Flip animations
20
+ | "flip-up"
21
+ | "flip-down"
22
+ | "flip-left"
23
+ | "flip-right"
24
+ // Slide animations
25
+ | "slide-up"
26
+ | "slide-down"
27
+ | "slide-left"
28
+ | "slide-right"
29
+ // Zoom animations
30
+ | "zoom-in"
31
+ | "zoom-in-up"
32
+ | "zoom-in-down"
33
+ | "zoom-in-left"
34
+ | "zoom-in-right"
35
+ | "zoom-out"
36
+ | "zoom-out-up"
37
+ | "zoom-out-down"
38
+ | "zoom-out-left"
39
+ | "zoom-out-right";
40
+
41
+ // AOS 缓动函数
42
+ export type AOSEasing =
43
+ | "ease"
44
+ | "linear"
45
+ | "ease-in"
46
+ | "ease-out"
47
+ | "ease-in-out"
48
+ | "ease-in-back"
49
+ | "ease-out-back"
50
+ | "ease-in-out-back"
51
+ | "ease-in-sine"
52
+ | "ease-out-sine"
53
+ | "ease-in-out-sine"
54
+ | "ease-in-quad"
55
+ | "ease-out-quad"
56
+ | "ease-in-out-quad"
57
+ | "ease-in-cubic"
58
+ | "ease-out-cubic"
59
+ | "ease-in-out-cubic"
60
+ | "ease-in-quart"
61
+ | "ease-out-quart"
62
+ | "ease-in-out-quart";
63
+
64
+ // AOS 锚点位置
65
+ export type AOSAnchorPlacement =
66
+ | "top-bottom"
67
+ | "top-center"
68
+ | "top-top"
69
+ | "center-bottom"
70
+ | "center-center"
71
+ | "center-top"
72
+ | "bottom-bottom"
73
+ | "bottom-center"
74
+ | "bottom-top";
75
+
76
+ /**
77
+ * 动画配置
78
+ * 使用 data-aos-* 格式的键名,可以直接通过 {...props} 展开到 HTML 元素上
79
+ */
80
+ export type AOSAnimationConfig = {
81
+ /**
82
+ * 动画类型
83
+ * 默认值: 无
84
+ */
85
+ "data-aos"?: AOSAnimation;
86
+
87
+ /**
88
+ * 动画偏移量(像素)
89
+ * 默认值: 120
90
+ * 说明: 元素距离视口多少像素时触发动画
91
+ */
92
+ "data-aos-offset"?: number | string;
93
+
94
+ /**
95
+ * 动画延迟(毫秒)
96
+ * 默认值: 0
97
+ * 可选值: 0-3000,步长 50
98
+ */
99
+ "data-aos-delay"?: number | string;
100
+
101
+ /**
102
+ * 动画持续时间(毫秒)
103
+ * 默认值: 400
104
+ * 可选值: 0-3000,步长 50
105
+ */
106
+ "data-aos-duration"?: number | string;
107
+
108
+ /**
109
+ * 缓动函数
110
+ * 默认值: ease
111
+ */
112
+ "data-aos-easing"?: AOSEasing;
113
+
114
+ /**
115
+ * 锚点位置
116
+ * 默认值: top-bottom
117
+ * 说明: 定义元素的哪个位置相对于窗口的哪个位置触发动画
118
+ * 格式: [元素位置]-[窗口位置]
119
+ */
120
+ "data-aos-anchor-placement"?: AOSAnchorPlacement;
121
+
122
+ /**
123
+ * 锚点元素选择器
124
+ * 说明: 使用另一个元素作为触发点
125
+ */
126
+ "data-aos-anchor"?: string;
127
+
128
+ /**
129
+ * 是否只执行一次
130
+ * 默认值: false
131
+ * 说明: 设置为 true 时,动画只在第一次滚动到时执行
132
+ */
133
+ "data-aos-once"?: boolean | "true" | "false";
134
+
135
+ /**
136
+ * 是否在移动设备上禁用
137
+ * 可选值: 'mobile' | 'phone' | 'tablet' | false
138
+ */
139
+ "data-aos-disable"?: "mobile" | "phone" | "tablet" | false;
140
+
141
+ /**
142
+ * 动画 ID
143
+ * 说明: 用于单独控制动画
144
+ */
145
+ "data-aos-id"?: string;
146
+ };
@@ -0,0 +1,53 @@
1
+ // 背景样式类型定义,支持tailwind类
2
+ export type ColorBackgroundConfig = {
3
+ id?: string;
4
+ type: "color";
5
+ className?: string; // 颜色 ,模糊,图案等,如 "bg-blue-500", "bg-gradient-to-r from-blue-500 to-purple-600"
6
+ };
7
+
8
+ export type BlurBackgroundConfig = {
9
+ id?: string;
10
+ type: "blur";
11
+ className?: string; // 模糊,如 "backdrop-blur"
12
+ };
13
+
14
+ export type ImageBackgroundConfig = {
15
+ id?: string;
16
+ type: "image";
17
+ className?: string; // 图片,如 "bg-cover bg-center bg-no-repeat"
18
+ mediaRef?: string; // 图片ref
19
+ url?: string; // 图片 URL
20
+ };
21
+
22
+ export type SvgBackgroundConfig = {
23
+ id?: string;
24
+ type: "svg";
25
+ className?: string; // 图案,如 "bg-dots-sm bg-gray-100"
26
+ code?: string; // SVG代码
27
+ };
28
+
29
+ export type VideoBackgroundConfig = {
30
+ id?: string;
31
+ type: "video";
32
+ className?: string; // 视频,如 "bg-cover bg-center bg-no-repeat"
33
+ mediaRef?: string; // 视频Ref
34
+ posterRef?: string; // 视频封面Ref
35
+ url?: string; // 视频 URL
36
+ poster?: string; // 视频封面图 URL
37
+ };
38
+
39
+ export type SplineBackgroundConfig = {
40
+ id?: string;
41
+ type: "spline";
42
+ className?: string; // Spline,如 "bg-cover bg-center bg-no-repeat"
43
+ mediaRef?: string; // Spline ID
44
+ url?: string; // Spline 场景 URL
45
+ };
46
+
47
+ export type BackgroundConfig =
48
+ | ColorBackgroundConfig
49
+ | BlurBackgroundConfig
50
+ | ImageBackgroundConfig
51
+ | SvgBackgroundConfig
52
+ | VideoBackgroundConfig
53
+ | SplineBackgroundConfig;
@@ -0,0 +1,80 @@
1
+ import { ResponsiveGridLayout } from "./types";
2
+
3
+ const oneCellLayout = {
4
+ id: "cell1",
5
+ colStart: 1,
6
+ colSpan: 12,
7
+ rowStart: 1,
8
+ };
9
+
10
+ //单行布局
11
+ export const layout1: ResponsiveGridLayout = {
12
+ lg: {
13
+ cols: 12,
14
+ cells: [oneCellLayout],
15
+ },
16
+ md: {
17
+ cols: 12,
18
+ cells: [oneCellLayout],
19
+ },
20
+ sm: {
21
+ cols: 12,
22
+ cells: [oneCellLayout],
23
+ },
24
+ };
25
+
26
+ export const layout2: ResponsiveGridLayout = {
27
+ lg: {
28
+ cols: 12,
29
+ cells: [
30
+ {
31
+ id: "cell1",
32
+ colStart: 1,
33
+ colSpan: 6,
34
+ rowStart: 1,
35
+ },
36
+ {
37
+ id: "cell2",
38
+ colStart: 7,
39
+ colSpan: 6,
40
+ rowStart: 1,
41
+ },
42
+ ],
43
+ },
44
+ md: {
45
+ cols: 12,
46
+ cells: [
47
+ {
48
+ id: "cell1",
49
+ colStart: 1,
50
+ colSpan: 6,
51
+ rowStart: 1,
52
+ },
53
+ {
54
+ id: "cell2",
55
+ colStart: 7,
56
+ colSpan: 6,
57
+ rowStart: 1,
58
+ },
59
+ ],
60
+ },
61
+ sm: {
62
+ cols: 12,
63
+ cells: [
64
+ {
65
+ id: "cell1",
66
+ colStart: 1,
67
+ colSpan: 12,
68
+ rowStart: 1,
69
+ },
70
+ {
71
+ id: "cell2",
72
+ colStart: 1,
73
+ colSpan: 12,
74
+ rowStart: 1,
75
+ },
76
+ ],
77
+ },
78
+ };
79
+
80
+ export const singleRowLayouts: ResponsiveGridLayout[] = [layout1, layout2];
@@ -0,0 +1,2 @@
1
+ export * from "./consts"
2
+ export * from "./types"
@@ -0,0 +1,35 @@
1
+ export type GridCellLayout = {
2
+ id: string;
3
+ /** 列起始位置 (1-based, 对应 col-start-*) */
4
+ colStart: number;
5
+ /** 列跨度 (对应 col-span-*) */
6
+ colSpan: number;
7
+ /** 行起始位置 (1-based, 对应 row-start-*) */
8
+ rowStart: number;
9
+ /** 行跨度 (对应 row-span-*) */
10
+ rowSpan?: number;
11
+ };
12
+
13
+ export type GridLayout = {
14
+ cells: GridCellLayout[];
15
+ cols: number;
16
+ //这个可以计算出来
17
+ //rows: number;
18
+ };
19
+
20
+ //@deprecated 后面废弃这个写法,直接用tailwind grid布局
21
+ //要不然,代码用物料写起来会异常复杂
22
+ export type ResponsiveGridLayout = {
23
+ [breakpoint: string]: GridLayout;
24
+ };
25
+
26
+ export type GridLayoutProps = {
27
+ //这里面添加列数,比如grid-cols-12, sm:grid-cols-6
28
+ className?: string;
29
+ };
30
+
31
+ export type GridCellProps = {
32
+ //这里面添加row-start, col-start, row-span, col-span,比如row-start-1, col-start-1, row-span-1, col-span-1
33
+ //sm:row-start-1, sm:col-start-1, sm:row-span-1, sm:col-span-1
34
+ className?: string;
35
+ };
@@ -0,0 +1,7 @@
1
+ export * from "./animation";
2
+ export * from "./grid";
3
+ export * from "./section";
4
+ export * from "./background";
5
+ export * from "./media";
6
+
7
+
@@ -0,0 +1,109 @@
1
+ import { ImageSizes, Media } from "@rxdrag/rxcms-models";
2
+ import { ImgHTMLAttributes } from "react";
3
+
4
+ export type FileFieldType =
5
+ | "thumbnail"
6
+ | "original"
7
+ | "small"
8
+ | "medium"
9
+ | "large"
10
+ | "resize";
11
+
12
+ export type ImageResize = {
13
+ width?: number;
14
+ height?: number;
15
+ };
16
+
17
+ export const DEFUALT_WIDTH = 100;
18
+ export const DEFUALT_HEIGHT = 100;
19
+
20
+ export const DEFAULT_SAMLL: ImageResize = {
21
+ width: 400,
22
+ height: 400,
23
+ };
24
+
25
+ export const DEFAULT_MEDIUM: ImageResize = {
26
+ width: 800,
27
+ height: 800,
28
+ };
29
+
30
+ export const DEFAULT_LARGE: ImageResize = {
31
+ width: 1200,
32
+ height: 1200,
33
+ };
34
+
35
+ //TODO:以后还要加transform参数
36
+ export type ImageProps = ImgHTMLAttributes<HTMLImageElement> & {
37
+ className?: string;
38
+ mediaId?: string;
39
+ //默认original
40
+ fileField?: FileFieldType;
41
+ resize?: ImageResize;
42
+ children?: React.ReactNode;
43
+ //为导出代码方便,如果设置了src,显示的时候可以忽略mediaId等
44
+ src?: string;
45
+ };
46
+
47
+ export const transformMeidaFields = (
48
+ field?: FileFieldType,
49
+ resize?: ImageResize,
50
+ images?: ImageSizes
51
+ ): string[] => {
52
+ const fields = ["original", "thumbnail"];
53
+ if (resize) {
54
+ fields.push(
55
+ `resize(width: ${resize.width || DEFUALT_WIDTH}, height: ${
56
+ resize.height || DEFUALT_HEIGHT
57
+ })`
58
+ );
59
+ }
60
+ if (field === "small") {
61
+ fields.push(
62
+ `small(width: ${images?.small?.width || DEFAULT_SAMLL.width}, height: ${
63
+ images?.small?.height || DEFAULT_SAMLL.height
64
+ })`
65
+ );
66
+ }
67
+ if (field === "medium") {
68
+ fields.push(
69
+ `medium(width: ${
70
+ images?.medium?.width || DEFAULT_MEDIUM.width
71
+ }, height: ${images?.medium?.height || DEFAULT_MEDIUM.height})`
72
+ );
73
+ }
74
+ if (field === "large") {
75
+ fields.push(
76
+ `large(width: ${images?.large?.width || DEFAULT_LARGE.width}, height: ${
77
+ images?.large?.height || DEFAULT_LARGE.height
78
+ })`
79
+ );
80
+ }
81
+ return fields;
82
+ };
83
+
84
+ export const extractShowSrc = (
85
+ field?: FileFieldType,
86
+ resize?: ImageResize,
87
+ media?: Media
88
+ ) => {
89
+ if (!media?.file) {
90
+ return "";
91
+ }
92
+ if (field === "thumbnail") {
93
+ return media.file.thumbnail;
94
+ }
95
+
96
+ if (field === "resize" && resize) {
97
+ return media.file.resize;
98
+ }
99
+ if (field === "small" && media.file.small) {
100
+ return media.file.small;
101
+ }
102
+ if (field === "medium" && media.file.medium) {
103
+ return media.file.medium;
104
+ }
105
+ if (field === "large" && media.file.large) {
106
+ return media.file.large;
107
+ }
108
+ return media.file.original;
109
+ };
@@ -0,0 +1,12 @@
1
+ import { AOSAnimationConfig } from "../animation";
2
+ import { BackgroundConfig } from "../background";
3
+
4
+ //可调参数有:内边距(4个),内边距(4个)。内容:内边距(4个),内边距(4个)
5
+ export type SectionProps = {
6
+ className?: string;
7
+ containerClassName?: string;
8
+ backgrounds?: BackgroundConfig[];
9
+ //动效
10
+ animation?: AOSAnimationConfig;
11
+ disableContainer?: boolean;
12
+ };
@@ -17,6 +17,10 @@ import {
17
17
  queryProducts,
18
18
  queryUserPosts,
19
19
  fulltextSearch,
20
+ queryOneEntity,
21
+ createUploadCredentials,
22
+ UploadOptions,
23
+ UploadSession,
20
24
  } from "./lib";
21
25
  import { IQueryOptions } from "@rxdrag/entify-lib";
22
26
  import { queryAllProducts } from "./lib/queryAllProducts";
@@ -24,7 +28,13 @@ import { queryPostSlugs } from "./lib/queryPostSlugs";
24
28
  import { queryUserIds } from "./lib/queryUserIds";
25
29
  import { IEntify, PostPatinateOptions, PostsOptions } from "./IEntify";
26
30
  import { queryWebsite } from "./lib/queryWebsite";
27
- import { Page, PageType, Product } from "@rxdrag/rxcms-models";
31
+ import {
32
+ Page,
33
+ PageType,
34
+ Product,
35
+ WebsitePart,
36
+ WebsitePartBoolExp,
37
+ } from "@rxdrag/rxcms-models";
28
38
  import { queryPageBySlug } from "./lib/queryPageBySlug";
29
39
  import { queryPageByType } from "./lib/queryPageByType";
30
40
 
@@ -52,6 +62,15 @@ export class Entify implements IEntify {
52
62
  );
53
63
  }
54
64
 
65
+ public async queryOneEntity<T extends WebsitePart = WebsitePart>(
66
+ options: IQueryOptions<T, WebsitePartBoolExp>
67
+ ) {
68
+ return await queryOneEntity<T, WebsitePartBoolExp>(
69
+ options,
70
+ this.envVariables
71
+ );
72
+ }
73
+
55
74
  public getLang() {
56
75
  return this.envVariables.language || "en-US";
57
76
  }
@@ -73,7 +92,12 @@ export class Entify implements IEntify {
73
92
  imageSize?: TSize,
74
93
  addonFields?: (keyof Product)[]
75
94
  ) {
76
- return await queryFeaturedProducts(count, imageSize, this.envVariables, addonFields);
95
+ return await queryFeaturedProducts(
96
+ count,
97
+ imageSize,
98
+ this.envVariables,
99
+ addonFields
100
+ );
77
101
  }
78
102
 
79
103
  public async getLatestPosts(count?: number, coverSize?: TSize) {
@@ -413,4 +437,10 @@ export class Entify implements IEntify {
413
437
 
414
438
  return paths;
415
439
  }
440
+
441
+ public async createUploadCredentials(
442
+ options: UploadOptions
443
+ ): Promise<UploadSession | null> {
444
+ return await createUploadCredentials(options, this.envVariables);
445
+ }
416
446
  }
@@ -1,6 +1,6 @@
1
1
  import { IQueryOptions, ListResult } from "@rxdrag/entify-lib";
2
2
  import { TSize } from "./types";
3
- import { ListConditions } from "./lib";
3
+ import { ListConditions, UploadOptions, UploadSession } from "./lib";
4
4
  import {
5
5
  TPost,
6
6
  TPostCategory,
@@ -8,7 +8,17 @@ import {
8
8
  TProductCategory,
9
9
  TUser,
10
10
  } from "./view-model";
11
- import { Lang, Page, PageType, Product, SearchIndex, Theme, Website } from "@rxdrag/rxcms-models";
11
+ import {
12
+ Lang,
13
+ Page,
14
+ PageType,
15
+ Product,
16
+ SearchIndex,
17
+ ThemeBranch,
18
+ Website,
19
+ WebsitePart,
20
+ } from "@rxdrag/rxcms-models";
21
+ import { WebsitePartBoolExp } from "@rxdrag/rxcms-models/";
12
22
 
13
23
  export type PostsOptions = {
14
24
  category?: string;
@@ -35,15 +45,24 @@ export interface IEntify {
35
45
  staticKey?: string
36
46
  ): Promise<ListResult<unknown> | undefined>;
37
47
 
48
+ queryOneEntity<T extends WebsitePart = WebsitePart>(options: IQueryOptions<T, WebsitePartBoolExp>): Promise<T | undefined>;
49
+
38
50
  getWebsite(): Promise<Website | undefined>;
39
51
 
40
- getTheme(): Promise<Theme | undefined>;
52
+ getTheme(): Promise<ThemeBranch | undefined>;
41
53
 
42
54
  getLangs(): Promise<Lang[] | undefined>;
43
55
 
44
- getFeaturedProducts(count?: number, imageSize?: TSize, addonFields?: (keyof Product)[]): Promise<TProduct[] | undefined>;
56
+ getFeaturedProducts(
57
+ count?: number,
58
+ imageSize?: TSize,
59
+ addonFields?: (keyof Product)[]
60
+ ): Promise<TProduct[] | undefined>;
45
61
 
46
- getLatestPosts(count?: number, coverSize?: TSize): Promise<TPost[] | undefined>;
62
+ getLatestPosts(
63
+ count?: number,
64
+ coverSize?: TSize
65
+ ): Promise<TPost[] | undefined>;
47
66
 
48
67
  getPosts(options: PostsOptions): Promise<TPost[] | undefined>;
49
68
 
@@ -124,9 +143,14 @@ export interface IEntify {
124
143
 
125
144
  getUserPosts(userId: string): Promise<TPost[] | undefined>;
126
145
 
127
- fulltextSearch(keyword: string, imageSize: TSize | undefined): Promise<ListResult<SearchIndex> | undefined>;
146
+ fulltextSearch(
147
+ keyword: string,
148
+ imageSize: TSize | undefined
149
+ ): Promise<ListResult<SearchIndex> | undefined>;
128
150
 
129
151
  getUserPaths(): Promise<unknown>;
130
152
 
131
153
  createPagination(totalItems: number, pageSize: number): unknown;
154
+
155
+ createUploadCredentials(options: UploadOptions): Promise<UploadSession | null>;
132
156
  }
@@ -0,0 +1,56 @@
1
+ import { createEntifyClient } from "./createEntifyClient";
2
+ import { EnvVariables } from "../types";
3
+
4
+ export type UploadOptions = {
5
+ mediaType: string;
6
+ uploadLength?: number;
7
+ uploadMetadata?: string;
8
+ };
9
+
10
+ export type UploadSession = {
11
+ platform: PlatformType | string;
12
+ uploadUrl?: string;
13
+ credentials?: unknown;
14
+ expiry?: number;
15
+ };
16
+
17
+ export enum PlatformType {
18
+ aliyun = "aliyun",
19
+ aliyunOss = "aliyun_oss",
20
+ cloudflareR2 = "cloudflare_r2",
21
+ cloudflareImages = "cloudflare_images",
22
+ cloudflareStream = "cloudflare_stream",
23
+ }
24
+
25
+ const rootField = "createUploadCredentials";
26
+
27
+ const createUploadCredentialsGql = `
28
+ mutation createUploadCredentials($options: UploadOptionsInput!) {
29
+ ${rootField}(options: $options) {
30
+ platform
31
+ credentials
32
+ uploadUrl
33
+ expiry
34
+ }
35
+ }
36
+ `;
37
+
38
+ export async function createUploadCredentials(
39
+ options: UploadOptions,
40
+ envVariables: EnvVariables
41
+ ): Promise<UploadSession | null> {
42
+ const entifyClient = createEntifyClient(envVariables);
43
+
44
+ const data = await entifyClient.client.request<{ [key: string]: UploadSession | null }>(
45
+ createUploadCredentialsGql,
46
+ { options }
47
+ );
48
+
49
+ const response = data?.[rootField];
50
+
51
+ if (!response) {
52
+ return null;
53
+ }
54
+
55
+ return response;
56
+ }