@opexa/portal-components 0.0.258 → 0.0.260

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 (59) hide show
  1. package/dist/client/hooks/useCamera.d.ts +11 -16
  2. package/dist/client/hooks/useCamera.js +29 -57
  3. package/dist/client/hooks/useUploadFileMutation.d.ts +4 -0
  4. package/dist/client/hooks/useUploadFileMutation.js +24 -0
  5. package/dist/client/hooks/useUploadImageFileMutation.d.ts +2 -2
  6. package/dist/client/hooks/useUploadImageFileMutation.js +2 -2
  7. package/dist/client/hooks/useUploadPrivateImageFileMutation.d.ts +4 -0
  8. package/dist/client/hooks/useUploadPrivateImageFileMutation.js +24 -0
  9. package/dist/components/Disclaimer/DisclaimerV2.js +2 -2
  10. package/dist/components/Disclaimer/TermsOfUse.js +0 -4
  11. package/dist/components/Search/Search.lazy.js +6 -2
  12. package/dist/components/SignIn/MobileNumberSignIn.js +1 -0
  13. package/dist/components/SignIn/utils.d.ts +1 -0
  14. package/dist/components/SignIn/utils.js +4 -0
  15. package/dist/components/shared/IdFrontImageField/IdFrontImageField.client.d.ts +15 -0
  16. package/dist/components/shared/IdFrontImageField/IdFrontImageField.client.js +140 -0
  17. package/dist/components/shared/IdFrontImageField/IdFrontImageField.d.ts +2 -0
  18. package/dist/components/shared/IdFrontImageField/IdFrontImageField.js +11 -0
  19. package/dist/components/shared/IdFrontImageField/IdFrontImageFieldContext.d.ts +6 -0
  20. package/dist/components/shared/IdFrontImageField/IdFrontImageFieldContext.js +2 -0
  21. package/dist/components/shared/IdFrontImageField/index.d.ts +1 -0
  22. package/dist/components/shared/IdFrontImageField/index.js +1 -0
  23. package/dist/components/shared/IdFrontImageField/useIdFrontImageField.d.ts +22 -0
  24. package/dist/components/shared/IdFrontImageField/useIdFrontImageField.js +111 -0
  25. package/dist/components/shared/SelfieImageField/SelfieImageField.client.d.ts +15 -0
  26. package/dist/components/shared/SelfieImageField/SelfieImageField.client.js +170 -0
  27. package/dist/components/shared/SelfieImageField/SelfieImageField.d.ts +2 -0
  28. package/dist/components/shared/SelfieImageField/SelfieImageField.js +11 -0
  29. package/dist/components/shared/SelfieImageField/SelfieImageFieldContext.d.ts +6 -0
  30. package/dist/components/shared/SelfieImageField/SelfieImageFieldContext.js +2 -0
  31. package/dist/components/shared/SelfieImageField/index.d.ts +1 -0
  32. package/dist/components/shared/SelfieImageField/index.js +1 -0
  33. package/dist/components/shared/SelfieImageField/useSelfieImageField.d.ts +23 -0
  34. package/dist/components/shared/SelfieImageField/useSelfieImageField.js +208 -0
  35. package/dist/handlers/deleteSession.d.ts +9 -0
  36. package/dist/handlers/deleteSession.js +19 -0
  37. package/dist/handlers/getHealthCheck.d.ts +9 -0
  38. package/dist/handlers/getHealthCheck.js +16 -0
  39. package/dist/handlers/getSession.d.ts +10 -0
  40. package/dist/handlers/getSession.js +63 -0
  41. package/dist/handlers/index.d.ts +40 -0
  42. package/dist/handlers/index.js +56 -0
  43. package/dist/handlers/patchSession.d.ts +10 -0
  44. package/dist/handlers/patchSession.js +26 -0
  45. package/dist/handlers/postAuthenticate.d.ts +10 -0
  46. package/dist/handlers/postAuthenticate.js +51 -0
  47. package/dist/handlers/postSession.d.ts +17 -0
  48. package/dist/handlers/postSession.js +78 -0
  49. package/dist/handlers/postTransformIdFrontImage.d.ts +3 -0
  50. package/dist/handlers/postTransformIdFrontImage.js +67 -0
  51. package/dist/handlers/postTransformSelfieImage.d.ts +3 -0
  52. package/dist/handlers/postTransformSelfieImage.js +71 -0
  53. package/dist/services/file.d.ts +17 -12
  54. package/dist/services/file.js +21 -1
  55. package/dist/services/queries.d.ts +2 -0
  56. package/dist/services/queries.js +36 -0
  57. package/dist/utils/mutationKeys.d.ts +2 -0
  58. package/dist/utils/mutationKeys.js +8 -0
  59. package/package.json +4 -3
@@ -0,0 +1,63 @@
1
+ import { addMinutes } from 'date-fns';
2
+ import { NextResponse } from 'next/server';
3
+ import { ACCESS_TOKEN_COOKIE_NAME, DOMAIN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
4
+ import { refreshSession } from '../services/auth.js';
5
+ export async function getSession(request) {
6
+ const accessToken = request.cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
7
+ const refreshToken = request.cookies.get(REFRESH_TOKEN_COOKIE_NAME)?.value;
8
+ const domain = request.cookies.get(DOMAIN_COOKIE_NAME)?.value;
9
+ if (!refreshToken) {
10
+ const response = NextResponse.json({
11
+ ok: true,
12
+ data: {
13
+ domain,
14
+ status: 'unauthenticated',
15
+ },
16
+ });
17
+ response.cookies.delete(ACCESS_TOKEN_COOKIE_NAME);
18
+ response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
19
+ return response;
20
+ }
21
+ if (!accessToken) {
22
+ try {
23
+ const data = await refreshSession({
24
+ headers: {
25
+ Authorization: `Bearer ${refreshToken}`,
26
+ },
27
+ });
28
+ const response = NextResponse.json({
29
+ ok: true,
30
+ data: {
31
+ status: 'authenticated',
32
+ domain,
33
+ token: data.accessToken,
34
+ },
35
+ });
36
+ response.cookies.set(ACCESS_TOKEN_COOKIE_NAME, data.accessToken, {
37
+ expires: addMinutes(new Date(), 9),
38
+ httpOnly: true,
39
+ sameSite: 'strict',
40
+ });
41
+ return response;
42
+ }
43
+ catch {
44
+ const response = NextResponse.json({
45
+ ok: true,
46
+ data: {
47
+ status: 'unauthenticated',
48
+ domain,
49
+ },
50
+ });
51
+ response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
52
+ return response;
53
+ }
54
+ }
55
+ return NextResponse.json({
56
+ ok: true,
57
+ data: {
58
+ status: 'authenticated',
59
+ domain,
60
+ token: accessToken,
61
+ },
62
+ });
63
+ }
@@ -0,0 +1,40 @@
1
+ import { NextResponse, type NextRequest } from 'next/server';
2
+ interface Params {
3
+ auth: string[];
4
+ }
5
+ interface Context {
6
+ params: Promise<Params>;
7
+ }
8
+ export declare const GET: (req: NextRequest, { params }: Context) => Promise<NextResponse<{
9
+ ok: true;
10
+ data?: never;
11
+ } | {
12
+ ok: false;
13
+ message: string;
14
+ __error?: unknown;
15
+ }> | NextResponse<{
16
+ ok: false;
17
+ message: string;
18
+ __error?: unknown;
19
+ } | {
20
+ ok: true;
21
+ data: Record<string, unknown>;
22
+ }> | NextResponse<{
23
+ ok: false;
24
+ message: string;
25
+ __error?: unknown;
26
+ } | {
27
+ ok: true;
28
+ data: import("../types").Session;
29
+ }>>;
30
+ export declare const DELETE: (req: NextRequest, { params }: Context) => Promise<NextResponse<{
31
+ ok: true;
32
+ data?: never;
33
+ } | {
34
+ ok: false;
35
+ message: string;
36
+ __error?: unknown;
37
+ }>>;
38
+ export declare const POST: (req: NextRequest, { params }: Context) => Promise<NextResponse>;
39
+ export declare const PATCH: (req: NextRequest, { params }: Context) => Promise<NextResponse>;
40
+ export {};
@@ -0,0 +1,56 @@
1
+ import { NextResponse } from 'next/server';
2
+ import { deleteSession } from './deleteSession.js';
3
+ import { getHealthCheck } from './getHealthCheck.js';
4
+ import { getSession } from './getSession.js';
5
+ import { patchSession } from './patchSession.js';
6
+ import { postAuthenticate } from './postAuthenticate.js';
7
+ import { postSession } from './postSession.js';
8
+ import { postTransformIdFrontImage } from './postTransformIdFrontImage.js';
9
+ import { postTransformSelfieImage } from './postTransformSelfieImage.js';
10
+ export const GET = async (req, { params }) => {
11
+ const { auth } = await params;
12
+ const path = auth[0];
13
+ if (path === 'health-check') {
14
+ return await getHealthCheck(req);
15
+ }
16
+ if (path === 'sessions') {
17
+ return await getSession(req);
18
+ }
19
+ return NextResponse.json({ ok: false, message: 'Not found' }, { status: 404 });
20
+ };
21
+ export const DELETE = async (req, { params }) => {
22
+ const { auth } = await params;
23
+ const path = auth[0];
24
+ if (path === 'sessions') {
25
+ return await deleteSession(req);
26
+ }
27
+ return NextResponse.json({ ok: false, message: 'Not found' }, { status: 404 });
28
+ };
29
+ export const POST = async (req, { params }) => {
30
+ const { auth } = await params;
31
+ const path = auth[0];
32
+ const subpath = auth[1];
33
+ if (path === 'sessions') {
34
+ return await postSession(req);
35
+ }
36
+ if (path === 'authenticate') {
37
+ return await postAuthenticate(req);
38
+ }
39
+ if (path === 'transformers') {
40
+ if (subpath === 'selfie-image') {
41
+ return await postTransformSelfieImage(req);
42
+ }
43
+ if (subpath === 'id-front-image') {
44
+ return await postTransformIdFrontImage(req);
45
+ }
46
+ }
47
+ return NextResponse.json({ ok: false, message: 'Not found' }, { status: 404 });
48
+ };
49
+ export const PATCH = async (req, { params }) => {
50
+ const { auth } = await params;
51
+ const path = auth[0];
52
+ if (path === 'sessions') {
53
+ return await patchSession(req);
54
+ }
55
+ return NextResponse.json({ ok: false, message: 'Not found' }, { status: 404 });
56
+ };
@@ -0,0 +1,10 @@
1
+ import type { NextRequest } from 'next/server';
2
+ import { NextResponse } from 'next/server';
3
+ export declare function patchSession(request: NextRequest): Promise<NextResponse<{
4
+ ok: true;
5
+ data?: never;
6
+ } | {
7
+ ok: false;
8
+ message: string;
9
+ __error?: unknown;
10
+ }>>;
@@ -0,0 +1,26 @@
1
+ import { addDays } from 'date-fns';
2
+ import { NextResponse } from 'next/server';
3
+ import { z } from 'zod';
4
+ import { DOMAIN_COOKIE_NAME } from '../constants/index.js';
5
+ const UpdateSessionDefinition = z.object({
6
+ domain: z.string().optional().nullable(),
7
+ });
8
+ export async function patchSession(request) {
9
+ const body = await request.json();
10
+ const parsed = UpdateSessionDefinition.safeParse(body);
11
+ if (!parsed.success) {
12
+ return NextResponse.json({
13
+ ok: false,
14
+ message: parsed.error.issues[0].message,
15
+ }, { status: 400 });
16
+ }
17
+ const response = NextResponse.json({ ok: true });
18
+ if (parsed.data.domain) {
19
+ response.cookies.set(DOMAIN_COOKIE_NAME, parsed.data.domain, {
20
+ expires: addDays(new Date(), 30),
21
+ httpOnly: true,
22
+ sameSite: 'strict',
23
+ });
24
+ }
25
+ return response;
26
+ }
@@ -0,0 +1,10 @@
1
+ import type { NextRequest } from 'next/server';
2
+ import { NextResponse } from 'next/server';
3
+ export declare function postAuthenticate(request: NextRequest): Promise<NextResponse<{
4
+ ok: true;
5
+ data?: never;
6
+ } | {
7
+ ok: false;
8
+ message: string;
9
+ __error?: unknown;
10
+ }>>;
@@ -0,0 +1,51 @@
1
+ import { addDays, addMinutes, subMinutes } from 'date-fns';
2
+ import { NextResponse } from 'next/server';
3
+ import { z } from 'zod';
4
+ import { ACCESS_TOKEN_COOKIE_NAME, DOMAIN_HEADER_KEY, RECAPTCHA_HEADER_KEY, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
5
+ import { authenticate } from '../services/auth.js';
6
+ const AuthenticateDefinition = z.object({
7
+ type: z.literal('SECURITY_QUESTION'),
8
+ token: z.string(),
9
+ secretAnswer: z.string(),
10
+ });
11
+ export async function postAuthenticate(request) {
12
+ const body = await request.json();
13
+ const parsed = AuthenticateDefinition.safeParse(body);
14
+ if (!parsed.success) {
15
+ return NextResponse.json({
16
+ ok: false,
17
+ message: parsed.error.issues[0].message,
18
+ }, { status: 400 });
19
+ }
20
+ const recaptcha = request.headers.get(RECAPTCHA_HEADER_KEY);
21
+ const domain = request.headers.get(DOMAIN_HEADER_KEY);
22
+ try {
23
+ const res = await authenticate(parsed.data, {
24
+ headers: {
25
+ ...(recaptcha && {
26
+ [RECAPTCHA_HEADER_KEY]: recaptcha,
27
+ }),
28
+ ...(domain && {
29
+ [DOMAIN_HEADER_KEY]: domain,
30
+ }),
31
+ },
32
+ });
33
+ const response = NextResponse.json({ ok: true }, { status: 201 });
34
+ response.cookies.set(ACCESS_TOKEN_COOKIE_NAME, res.accessToken, {
35
+ expires: addMinutes(new Date(), 9),
36
+ httpOnly: true,
37
+ });
38
+ response.cookies.set(REFRESH_TOKEN_COOKIE_NAME, res.refreshToken, {
39
+ expires: subMinutes(addDays(new Date(), 30), 1),
40
+ httpOnly: true,
41
+ });
42
+ return response;
43
+ }
44
+ catch (e) {
45
+ return NextResponse.json({
46
+ ok: false,
47
+ message: 'Unauthorized',
48
+ __error: e,
49
+ }, { status: 401 });
50
+ }
51
+ }
@@ -0,0 +1,17 @@
1
+ import type { NextRequest } from 'next/server';
2
+ import { NextResponse } from 'next/server';
3
+ export declare function postSession(request: NextRequest): Promise<NextResponse<{
4
+ ok: true;
5
+ data?: never;
6
+ } | {
7
+ ok: false;
8
+ message: string;
9
+ __error?: unknown;
10
+ }> | NextResponse<{
11
+ ok: false;
12
+ message: string;
13
+ __error?: unknown;
14
+ } | {
15
+ ok: true;
16
+ data: import("../types").SecurityQuestionAuthenticator | null;
17
+ }>>;
@@ -0,0 +1,78 @@
1
+ import { addDays, addMinutes, subMinutes } from 'date-fns';
2
+ import { NextResponse } from 'next/server';
3
+ import { z } from 'zod';
4
+ import { ACCESS_TOKEN_COOKIE_NAME, DOMAIN_HEADER_KEY, RECAPTCHA_HEADER_KEY, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
5
+ import { createSession } from '../services/auth.js';
6
+ const CreateSessionDefinition = z.union([
7
+ z.object({
8
+ type: z.literal('NAME_AND_PASSWORD'),
9
+ name: z.string(),
10
+ password: z.string(),
11
+ }),
12
+ z.object({
13
+ type: z.literal('MOBILE_NUMBER'),
14
+ mobileNumber: z.string(),
15
+ verificationCode: z.string(),
16
+ }),
17
+ z.object({
18
+ type: z.literal('MAYA'),
19
+ session: z.string(),
20
+ }),
21
+ z.object({
22
+ type: z.union([
23
+ z.literal('SOCIALS'),
24
+ z.literal('CABINET'),
25
+ z.literal('SINGLE_USE_TOKEN'),
26
+ ]),
27
+ token: z.string(),
28
+ }),
29
+ ]);
30
+ export async function postSession(request) {
31
+ const body = await request.json();
32
+ const parsed = CreateSessionDefinition.safeParse(body);
33
+ if (!parsed.success) {
34
+ return NextResponse.json({
35
+ ok: false,
36
+ message: parsed.error.issues[0].message,
37
+ }, { status: 400 });
38
+ }
39
+ const recaptcha = request.headers.get(RECAPTCHA_HEADER_KEY);
40
+ const domain = request.headers.get(DOMAIN_HEADER_KEY);
41
+ try {
42
+ const res = await createSession(parsed.data, {
43
+ headers: {
44
+ ...(recaptcha && {
45
+ [RECAPTCHA_HEADER_KEY]: recaptcha,
46
+ }),
47
+ ...(domain && {
48
+ [DOMAIN_HEADER_KEY]: domain,
49
+ }),
50
+ },
51
+ });
52
+ if (res.authenticator) {
53
+ return NextResponse.json({
54
+ ok: true,
55
+ data: res.authenticator,
56
+ });
57
+ }
58
+ const response = NextResponse.json({ ok: true, data: null }, { status: 201 });
59
+ response.cookies.set(ACCESS_TOKEN_COOKIE_NAME, res.accessToken, {
60
+ expires: addMinutes(new Date(), 9),
61
+ httpOnly: true,
62
+ sameSite: 'strict',
63
+ });
64
+ response.cookies.set(REFRESH_TOKEN_COOKIE_NAME, res.refreshToken, {
65
+ expires: subMinutes(addDays(new Date(), 30), 1),
66
+ httpOnly: true,
67
+ sameSite: 'strict',
68
+ });
69
+ return response;
70
+ }
71
+ catch (e) {
72
+ return NextResponse.json({
73
+ ok: false,
74
+ message: 'Unauthorized',
75
+ __error: e,
76
+ }, { status: 401 });
77
+ }
78
+ }
@@ -0,0 +1,3 @@
1
+ import type { NextRequest } from 'next/server';
2
+ import { NextResponse } from 'next/server';
3
+ export declare function postTransformIdFrontImage(request: NextRequest): Promise<NextResponse<unknown>>;
@@ -0,0 +1,67 @@
1
+ import { NextResponse } from 'next/server';
2
+ import sharp from 'sharp';
3
+ import { z } from 'zod';
4
+ import { validateFile } from '../utils/validateFile.js';
5
+ const TransformIdFrontImageDefinition = z.object({
6
+ image: z.instanceof(File).superRefine((file, context) => {
7
+ const error = validateFile(file);
8
+ if (error) {
9
+ context.addIssue({
10
+ code: z.ZodIssueCode.custom,
11
+ message: error.message,
12
+ });
13
+ }
14
+ }),
15
+ cropTop: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
16
+ cropLeft: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
17
+ cropWidth: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
18
+ cropHeight: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
19
+ });
20
+ export async function postTransformIdFrontImage(request) {
21
+ const form = await request.formData();
22
+ const parsed = TransformIdFrontImageDefinition.safeParse({
23
+ image: form.get('image'),
24
+ cropTop: form.get('cropTop'),
25
+ cropLeft: form.get('cropLeft'),
26
+ cropWidth: form.get('cropWidth'),
27
+ cropHeight: form.get('cropHeight'),
28
+ });
29
+ if (!parsed.success) {
30
+ return NextResponse.json({
31
+ ok: false,
32
+ message: parsed.error.issues[0].message,
33
+ __error: parsed.error,
34
+ }, { status: 400 });
35
+ }
36
+ const file = parsed.data.image;
37
+ const arrayBuffer = await file.arrayBuffer();
38
+ const buffer = Buffer.from(arrayBuffer);
39
+ const cropped = await sharp(buffer)
40
+ .extract({
41
+ top: parsed.data.cropTop,
42
+ left: parsed.data.cropLeft,
43
+ width: parsed.data.cropWidth,
44
+ height: parsed.data.cropHeight,
45
+ })
46
+ .resize({
47
+ width: 1200,
48
+ height: 757,
49
+ kernel: sharp.kernel.lanczos3,
50
+ withoutEnlargement: true,
51
+ })
52
+ .modulate({
53
+ brightness: 1.025,
54
+ saturation: 1.025,
55
+ })
56
+ .median(3)
57
+ .blur()
58
+ .sharpen()
59
+ .webp()
60
+ .toBuffer();
61
+ return new NextResponse(cropped, {
62
+ headers: {
63
+ 'Content-Type': 'image/webp',
64
+ 'Content-Disposition': `inline; filename="id-front-${Date.now()}.webp"`,
65
+ },
66
+ });
67
+ }
@@ -0,0 +1,3 @@
1
+ import type { NextRequest } from 'next/server';
2
+ import { NextResponse } from 'next/server';
3
+ export declare function postTransformSelfieImage(request: NextRequest): Promise<NextResponse<unknown>>;
@@ -0,0 +1,71 @@
1
+ import { NextResponse } from 'next/server';
2
+ import sharp from 'sharp';
3
+ import { z } from 'zod';
4
+ import { validateFile } from '../utils/validateFile.js';
5
+ const TransformSelfieImageDefinition = z.object({
6
+ image: z.instanceof(File).superRefine((file, context) => {
7
+ const error = validateFile(file);
8
+ if (error) {
9
+ context.addIssue({
10
+ code: z.ZodIssueCode.custom,
11
+ message: error.message,
12
+ });
13
+ }
14
+ }),
15
+ cropTop: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
16
+ cropLeft: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
17
+ cropWidth: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
18
+ cropHeight: z.number().or(z.string().transform((v) => Math.round(Number(v)))),
19
+ });
20
+ export async function postTransformSelfieImage(request) {
21
+ const form = await request.formData();
22
+ const parsed = TransformSelfieImageDefinition.safeParse({
23
+ image: form.get('image'),
24
+ cropTop: form.get('cropTop'),
25
+ cropLeft: form.get('cropLeft'),
26
+ cropWidth: form.get('cropWidth'),
27
+ cropHeight: form.get('cropHeight'),
28
+ });
29
+ if (!parsed.success) {
30
+ return NextResponse.json({
31
+ ok: false,
32
+ message: parsed.error.issues[0].message,
33
+ __error: parsed.error,
34
+ }, { status: 400 });
35
+ }
36
+ const file = parsed.data.image;
37
+ const arrayBuffer = await file.arrayBuffer();
38
+ const buffer = Buffer.from(arrayBuffer);
39
+ const cropped = await sharp(buffer)
40
+ .extract({
41
+ top: parsed.data.cropTop,
42
+ left: parsed.data.cropLeft,
43
+ width: parsed.data.cropWidth,
44
+ height: parsed.data.cropHeight,
45
+ })
46
+ .resize({
47
+ width: 1200,
48
+ height: 1200,
49
+ kernel: sharp.kernel.lanczos3,
50
+ withoutEnlargement: true,
51
+ })
52
+ .sharpen({
53
+ sigma: 1.15,
54
+ m1: 2.0,
55
+ m2: 5.0,
56
+ })
57
+ .modulate({
58
+ brightness: 1.025,
59
+ saturation: 1.025,
60
+ })
61
+ .median(3)
62
+ .blur()
63
+ .webp()
64
+ .toBuffer();
65
+ return new NextResponse(cropped, {
66
+ headers: {
67
+ 'Content-Type': 'image/webp',
68
+ 'Content-Disposition': `inline; filename="selfie-${Date.now()}.webp"`,
69
+ },
70
+ });
71
+ }
@@ -7,7 +7,7 @@ export interface FileQueryVariables {
7
7
  id: string;
8
8
  }
9
9
  export declare const getFile: (id: string, options?: GraphQLRequestOptions) => Promise<File | null>;
10
- export type UploadPrivateImageFileError = {
10
+ export type UploadFileError = {
11
11
  name: 'FileFormatNotSupportedError';
12
12
  message: string;
13
13
  } | {
@@ -17,17 +17,22 @@ export type UploadPrivateImageFileError = {
17
17
  name: 'FileSizeTooBigError';
18
18
  message: string;
19
19
  };
20
- export interface UploadPrivateImageFileMutation {
21
- uploadPrivateImageFile?: null | UploadPrivateImageFileError;
22
- }
23
- export interface UploadPrivateImageFileMutationVariables {
24
- input: {
25
- id: string;
26
- file: globalThis.File;
27
- };
28
- }
29
- export interface UploadPrivateImageFileInput {
20
+ export interface UploadFileInput {
30
21
  id: string;
31
22
  file: globalThis.File;
32
23
  }
33
- export declare const uploadPrivateImageFile: (input: UploadPrivateImageFileInput, options?: GraphQLRequestOptions) => Promise<void>;
24
+ export interface UploadFileMutationVariables {
25
+ input: UploadFileInput;
26
+ }
27
+ export interface UploadFileMutation {
28
+ uploadFile?: null | UploadFileError;
29
+ }
30
+ export declare const uploadFile: (input: UploadFileInput, options?: GraphQLRequestOptions) => Promise<void>;
31
+ export interface UploadImageFileMutation {
32
+ uploadImageFile?: null | UploadFileError;
33
+ }
34
+ export declare const uploadImageFile: (input: UploadFileInput, options?: GraphQLRequestOptions) => Promise<void>;
35
+ export interface UploadPrivateImageFileMutation {
36
+ uploadPrivateImageFile?: null | UploadFileError;
37
+ }
38
+ export declare const uploadPrivateImageFile: (input: UploadFileInput, options?: GraphQLRequestOptions) => Promise<void>;
@@ -1,11 +1,31 @@
1
1
  import { cache } from 'react';
2
2
  import { FILE_GRAPHQL_ENDPOINT } from '../constants/index.js';
3
3
  import { graphqlRequest, graphqlUpload, } from './graphqlRequest.js';
4
- import { FILE, UPLOAD_PRIVATE_IMAGE_FILE } from './queries.js';
4
+ import { FILE, UPLOAD_FILE, UPLOAD_IMAGE_FILE, UPLOAD_PRIVATE_IMAGE_FILE, } from './queries.js';
5
5
  export const getFile = cache(async (id, options) => {
6
6
  const res = await graphqlRequest(FILE_GRAPHQL_ENDPOINT, FILE, { id }, options);
7
7
  return res.node ?? null;
8
8
  });
9
+ export const uploadFile = async (input, options) => {
10
+ const res = await graphqlUpload(FILE_GRAPHQL_ENDPOINT, UPLOAD_FILE, { input }, options);
11
+ if (res.uploadFile) {
12
+ const error = new Error();
13
+ error.name = res.uploadFile.name;
14
+ error.message = ERROR_CODES_MESSAGE_MAP[res.uploadFile.name];
15
+ Error.captureStackTrace?.(error, uploadFile);
16
+ throw error;
17
+ }
18
+ };
19
+ export const uploadImageFile = async (input, options) => {
20
+ const res = await graphqlUpload(FILE_GRAPHQL_ENDPOINT, UPLOAD_IMAGE_FILE, { input }, options);
21
+ if (res.uploadImageFile) {
22
+ const error = new Error();
23
+ error.name = res.uploadImageFile.name;
24
+ error.message = ERROR_CODES_MESSAGE_MAP[res.uploadImageFile.name];
25
+ Error.captureStackTrace?.(error, uploadImageFile);
26
+ throw error;
27
+ }
28
+ };
9
29
  export const uploadPrivateImageFile = async (input, options) => {
10
30
  const res = await graphqlUpload(FILE_GRAPHQL_ENDPOINT, UPLOAD_PRIVATE_IMAGE_FILE, { input }, options);
11
31
  if (res.uploadPrivateImageFile) {
@@ -1,5 +1,7 @@
1
1
  export declare const FILE_FRAGMENT = "\n fragment FileFragment on File {\n id\n url\n status\n }\n";
2
2
  export declare const FILE = "\n \n fragment FileFragment on File {\n id\n url\n status\n }\n\n\n query File($id: ObjectId!) {\n node(id: $id) {\n ... on File {\n ...FileFragment\n }\n }\n }\n";
3
+ export declare const UPLOAD_FILE = "\n mutation UploadFile($input: UploadFileInput!) {\n uploadFile(input: $input) {\n ... on FileFormatNotSupportedError {\n name: __typename\n message\n }\n ... on FileNameTooLongError {\n name: __typename\n message\n }\n ... on FileSizeTooBigError {\n name: __typename\n message\n }\n }\n }\n";
4
+ export declare const UPLOAD_IMAGE_FILE = "\n mutation UploadImageFile($input: UploadFileInput!) {\n uploadImageFile(input: $input) {\n ... on FileFormatNotSupportedError {\n name: __typename\n message\n }\n ... on FileNameTooLongError {\n name: __typename\n message\n }\n ... on FileSizeTooBigError {\n name: __typename\n message\n }\n }\n }\n";
3
5
  export declare const UPLOAD_PRIVATE_IMAGE_FILE = "\n mutation UploadPrivateImageFile($input: UploadFileInput!) {\n uploadPrivateImageFile(input: $input) {\n ... on FileFormatNotSupportedError {\n name: __typename\n message\n }\n ... on FileNameTooLongError {\n name: __typename\n message\n }\n ... on FileSizeTooBigError {\n name: __typename\n message\n }\n }\n }\n";
4
6
  export declare const WALLET = "\n query Wallet {\n wallet {\n balance\n }\n }\n";
5
7
  export declare const POINTS_WALLET = "\n query PointsWallet {\n pointsWallet {\n id\n points\n account\n dateTimeCreated\n }\n }\n";
@@ -16,6 +16,42 @@ export const FILE = /* GraphQL */ `
16
16
  }
17
17
  }
18
18
  `;
19
+ export const UPLOAD_FILE = /* GraphQL */ `
20
+ mutation UploadFile($input: UploadFileInput!) {
21
+ uploadFile(input: $input) {
22
+ ... on FileFormatNotSupportedError {
23
+ name: __typename
24
+ message
25
+ }
26
+ ... on FileNameTooLongError {
27
+ name: __typename
28
+ message
29
+ }
30
+ ... on FileSizeTooBigError {
31
+ name: __typename
32
+ message
33
+ }
34
+ }
35
+ }
36
+ `;
37
+ export const UPLOAD_IMAGE_FILE = /* GraphQL */ `
38
+ mutation UploadImageFile($input: UploadFileInput!) {
39
+ uploadImageFile(input: $input) {
40
+ ... on FileFormatNotSupportedError {
41
+ name: __typename
42
+ message
43
+ }
44
+ ... on FileNameTooLongError {
45
+ name: __typename
46
+ message
47
+ }
48
+ ... on FileSizeTooBigError {
49
+ name: __typename
50
+ message
51
+ }
52
+ }
53
+ }
54
+ `;
19
55
  export const UPLOAD_PRIVATE_IMAGE_FILE = /* GraphQL */ `
20
56
  mutation UploadPrivateImageFile($input: UploadFileInput!) {
21
57
  uploadPrivateImageFile(input: $input) {
@@ -32,6 +32,8 @@ export declare const getSignOutMutationKey: () => MutationKey;
32
32
  export declare const getSignUpMutationKey: () => MutationKey;
33
33
  export declare const getCompleteOnboardingMutationKey: () => MutationKey;
34
34
  export declare const getSkipOnboardingMutationKey: () => MutationKey;
35
+ export declare const getUploadFileMutationKey: () => MutationKey;
35
36
  export declare const getUploadImageFileMutationKey: () => MutationKey;
37
+ export declare const getUploadPrivateImageFileMutationKey: () => MutationKey;
36
38
  export declare const getResetPasswordMutationKey: () => MutationKey;
37
39
  export declare const getUpdateSessionMutationKey: () => MutationKey;
@@ -122,10 +122,18 @@ export const getSkipOnboardingMutationKey = () => [
122
122
  PARENT_KEY,
123
123
  'skipOnboarding',
124
124
  ];
125
+ export const getUploadFileMutationKey = () => [
126
+ PARENT_KEY,
127
+ 'uploadFile',
128
+ ];
125
129
  export const getUploadImageFileMutationKey = () => [
126
130
  PARENT_KEY,
127
131
  'uploadImageFile',
128
132
  ];
133
+ export const getUploadPrivateImageFileMutationKey = () => [
134
+ PARENT_KEY,
135
+ 'uploadPrivateImageFile',
136
+ ];
129
137
  export const getResetPasswordMutationKey = () => [
130
138
  PARENT_KEY,
131
139
  'resetPassword',