@betterinternship/core 2.3.0 → 2.3.2

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.
@@ -1,184 +1,184 @@
1
- import { v4 as uuid } from 'uuid';
2
- import { pb } from './pb.js';
3
- import * as generator from 'generate-password';
4
- export class ConsumerService {
5
- async findOne(id) {
6
- return await pb.collection('users').getOne(id);
7
- }
8
- async findAll() {
9
- return await pb.collection('users').getFullList();
10
- }
11
- async register(id, email) {
12
- try {
13
- return await pb.collection('users').getOne(id);
14
- }
15
- catch (error) {
16
- const e = error;
17
- if (e.status !== 404)
18
- throw error;
19
- }
20
- const password = generator.generate({
21
- length: 10,
22
- numbers: true,
23
- symbols: true,
24
- uppercase: true,
25
- lowercase: true,
26
- strict: true,
27
- });
28
- return await pb.collection('users').create({
29
- id,
30
- email,
31
- password,
32
- passwordConfirm: password,
33
- last_reads: {},
34
- last_unreads: {},
35
- conversations: [],
36
- });
37
- }
38
- async setLastRead(id, conversationId, message) {
39
- const subscriber = await pb.collection('users').getOne(id);
40
- const last_reads = subscriber.last_reads;
41
- const last_unreads = subscriber.last_unreads;
42
- return await pb.collection('users').update(id, {
43
- last_reads: {
44
- ...last_reads,
45
- [conversationId]: last_reads?.[conversationId]?.timestamp < message.timestamp
46
- ? message
47
- : last_reads?.[conversationId],
48
- },
49
- last_unreads: {
50
- ...last_unreads,
51
- [conversationId]: last_unreads?.[conversationId]?.timestamp < message.timestamp
52
- ? message
53
- : last_unreads?.[conversationId],
54
- },
55
- });
56
- }
57
- async authenticateAs(id) {
58
- const asUser = await pb.collection('users').impersonate(id, 60 * 60 * 24);
59
- const token = asUser.authStore.token;
60
- const record = asUser.authStore.record;
61
- return { token, user: record };
62
- }
63
- }
64
- export class MessageService {
65
- consumerService = new ConsumerService();
66
- conversationService = new ConversationService();
67
- async updateConversationUnread(subscriberId, conversationId, message) {
68
- let subscriber;
69
- try {
70
- subscriber = await this.consumerService.findOne(subscriberId);
71
- }
72
- catch (error) {
73
- const e = error;
74
- if (e.status !== 404)
75
- throw error;
76
- subscriber = await this.consumerService.register(subscriberId, '');
77
- }
78
- await pb.collection('users').update(subscriberId, {
79
- last_unreads: {
80
- ...subscriber.last_unreads,
81
- [conversationId]: subscriber.last_unreads?.[conversationId]?.timestamp <
82
- message.timestamp
83
- ? message
84
- : subscriber.last_unreads?.[conversationId],
85
- },
86
- });
87
- }
88
- async send(senderId, conversationId, messageContent) {
89
- const message = {
90
- sender_id: senderId,
91
- message: messageContent,
92
- timestamp: new Date().getTime(),
93
- };
94
- const conversation = await this.conversationService.appendMessage(conversationId, message);
95
- await this.consumerService.setLastRead(senderId, conversationId, message);
96
- await Promise.all(conversation.subscribers.map((subscriberId) => this.updateConversationUnread(subscriberId, conversationId, message)));
97
- return message;
98
- }
99
- async read(consumerId, conversationId) {
100
- const consumer = await pb.collection('users').getOne(consumerId);
101
- const conversation = await pb
102
- .collection('conversations')
103
- .getOne(conversationId);
104
- await pb.collection('users').update(consumerId, {
105
- last_reads: {
106
- ...consumer.last_reads,
107
- [conversationId]: conversation.last_message,
108
- },
109
- last_unreads: {
110
- ...consumer.last_unreads,
111
- [conversationId]: conversation.last_message,
112
- },
113
- });
114
- return conversation.last_message;
115
- }
116
- async digest(consumerId, conversationId) {
117
- const consumer = await pb.collection('users').getOne(consumerId);
118
- const conversation = await pb
119
- .collection('conversations')
120
- .getOne(conversationId);
121
- await pb.collection('users').update(consumerId, {
122
- last_unreads: {
123
- ...consumer.last_unreads,
124
- [conversationId]: {
125
- ...conversation.last_message,
126
- digested: true,
127
- },
128
- },
129
- });
130
- return { ...conversation.last_message, digested: true };
131
- }
132
- }
133
- export class ConversationService {
134
- consumerService = new ConsumerService();
135
- async findOne(id) {
136
- return await pb.collection('conversations').getOne(id);
137
- }
138
- async appendMessage(conversationId, message) {
139
- const conversation = await this.findOne(conversationId);
140
- return await pb.collection('conversations').update(conversationId, {
141
- contents: [...conversation.contents, message],
142
- last_message: message,
143
- });
144
- }
145
- async subscribe(subscriberId, conversationId) {
146
- const conversation = await this.findOne(conversationId);
147
- const subscriber = await this.consumerService.findOne(subscriberId);
148
- await pb.collection('users').update(subscriberId, {
149
- conversations: [...subscriber.conversations, conversationId],
150
- });
151
- return await pb.collection('conversations').update(conversationId, {
152
- subscribers: [...conversation.subscribers, subscriberId],
153
- });
154
- }
155
- async getSubscriptions(subscriberId) {
156
- return await pb.collection('conversations').getFullList({
157
- filter: `subscribers ~ '${subscriberId}'`,
158
- });
159
- }
160
- async findExisting(userId, employerId) {
161
- return await pb
162
- .collection('conversations')
163
- .getFirstListItem(`subscribers ~ '${userId}' && subscribers ~ '${employerId}'`);
164
- }
165
- async checkIfSubscribed(subscriberId, conversationId) {
166
- const conversation = await this.findOne(conversationId);
167
- if (!conversation)
168
- return false;
169
- if (!conversation.subscribers.includes(subscriberId))
170
- return false;
171
- return true;
172
- }
173
- async create(userId, employerId) {
174
- const conversationId = uuid();
175
- const newConversation = await pb.collection('conversations').create({
176
- id: conversationId,
177
- subscribers: [userId, employerId],
178
- contents: [],
179
- last_message: {},
180
- });
181
- return newConversation;
182
- }
183
- }
1
+ import { v4 as uuid } from 'uuid';
2
+ import { pb } from './pb.js';
3
+ import * as generator from 'generate-password';
4
+ export class ConsumerService {
5
+ async findOne(id) {
6
+ return await pb.collection('users').getOne(id);
7
+ }
8
+ async findAll() {
9
+ return await pb.collection('users').getFullList();
10
+ }
11
+ async register(id, email) {
12
+ try {
13
+ return await pb.collection('users').getOne(id);
14
+ }
15
+ catch (error) {
16
+ const e = error;
17
+ if (e.status !== 404)
18
+ throw error;
19
+ }
20
+ const password = generator.generate({
21
+ length: 10,
22
+ numbers: true,
23
+ symbols: true,
24
+ uppercase: true,
25
+ lowercase: true,
26
+ strict: true,
27
+ });
28
+ return await pb.collection('users').create({
29
+ id,
30
+ email,
31
+ password,
32
+ passwordConfirm: password,
33
+ last_reads: {},
34
+ last_unreads: {},
35
+ conversations: [],
36
+ });
37
+ }
38
+ async setLastRead(id, conversationId, message) {
39
+ const subscriber = await pb.collection('users').getOne(id);
40
+ const last_reads = subscriber.last_reads;
41
+ const last_unreads = subscriber.last_unreads;
42
+ return await pb.collection('users').update(id, {
43
+ last_reads: {
44
+ ...last_reads,
45
+ [conversationId]: last_reads?.[conversationId]?.timestamp < message.timestamp
46
+ ? message
47
+ : last_reads?.[conversationId],
48
+ },
49
+ last_unreads: {
50
+ ...last_unreads,
51
+ [conversationId]: last_unreads?.[conversationId]?.timestamp < message.timestamp
52
+ ? message
53
+ : last_unreads?.[conversationId],
54
+ },
55
+ });
56
+ }
57
+ async authenticateAs(id) {
58
+ const asUser = await pb.collection('users').impersonate(id, 60 * 60 * 24);
59
+ const token = asUser.authStore.token;
60
+ const record = asUser.authStore.record;
61
+ return { token, user: record };
62
+ }
63
+ }
64
+ export class MessageService {
65
+ consumerService = new ConsumerService();
66
+ conversationService = new ConversationService();
67
+ async updateConversationUnread(subscriberId, conversationId, message) {
68
+ let subscriber;
69
+ try {
70
+ subscriber = await this.consumerService.findOne(subscriberId);
71
+ }
72
+ catch (error) {
73
+ const e = error;
74
+ if (e.status !== 404)
75
+ throw error;
76
+ subscriber = await this.consumerService.register(subscriberId, '');
77
+ }
78
+ await pb.collection('users').update(subscriberId, {
79
+ last_unreads: {
80
+ ...subscriber.last_unreads,
81
+ [conversationId]: subscriber.last_unreads?.[conversationId]?.timestamp <
82
+ message.timestamp
83
+ ? message
84
+ : subscriber.last_unreads?.[conversationId],
85
+ },
86
+ });
87
+ }
88
+ async send(senderId, conversationId, messageContent) {
89
+ const message = {
90
+ sender_id: senderId,
91
+ message: messageContent,
92
+ timestamp: new Date().getTime(),
93
+ };
94
+ const conversation = await this.conversationService.appendMessage(conversationId, message);
95
+ await this.consumerService.setLastRead(senderId, conversationId, message);
96
+ await Promise.all(conversation.subscribers.map((subscriberId) => this.updateConversationUnread(subscriberId, conversationId, message)));
97
+ return message;
98
+ }
99
+ async read(consumerId, conversationId) {
100
+ const consumer = await pb.collection('users').getOne(consumerId);
101
+ const conversation = await pb
102
+ .collection('conversations')
103
+ .getOne(conversationId);
104
+ await pb.collection('users').update(consumerId, {
105
+ last_reads: {
106
+ ...consumer.last_reads,
107
+ [conversationId]: conversation.last_message,
108
+ },
109
+ last_unreads: {
110
+ ...consumer.last_unreads,
111
+ [conversationId]: conversation.last_message,
112
+ },
113
+ });
114
+ return conversation.last_message;
115
+ }
116
+ async digest(consumerId, conversationId) {
117
+ const consumer = await pb.collection('users').getOne(consumerId);
118
+ const conversation = await pb
119
+ .collection('conversations')
120
+ .getOne(conversationId);
121
+ await pb.collection('users').update(consumerId, {
122
+ last_unreads: {
123
+ ...consumer.last_unreads,
124
+ [conversationId]: {
125
+ ...conversation.last_message,
126
+ digested: true,
127
+ },
128
+ },
129
+ });
130
+ return { ...conversation.last_message, digested: true };
131
+ }
132
+ }
133
+ export class ConversationService {
134
+ consumerService = new ConsumerService();
135
+ async findOne(id) {
136
+ return await pb.collection('conversations').getOne(id);
137
+ }
138
+ async appendMessage(conversationId, message) {
139
+ const conversation = await this.findOne(conversationId);
140
+ return await pb.collection('conversations').update(conversationId, {
141
+ contents: [...conversation.contents, message],
142
+ last_message: message,
143
+ });
144
+ }
145
+ async subscribe(subscriberId, conversationId) {
146
+ const conversation = await this.findOne(conversationId);
147
+ const subscriber = await this.consumerService.findOne(subscriberId);
148
+ await pb.collection('users').update(subscriberId, {
149
+ conversations: [...subscriber.conversations, conversationId],
150
+ });
151
+ return await pb.collection('conversations').update(conversationId, {
152
+ subscribers: [...conversation.subscribers, subscriberId],
153
+ });
154
+ }
155
+ async getSubscriptions(subscriberId) {
156
+ return await pb.collection('conversations').getFullList({
157
+ filter: `subscribers ~ '${subscriberId}'`,
158
+ });
159
+ }
160
+ async findExisting(userId, employerId) {
161
+ return await pb
162
+ .collection('conversations')
163
+ .getFirstListItem(`subscribers ~ '${userId}' && subscribers ~ '${employerId}'`);
164
+ }
165
+ async checkIfSubscribed(subscriberId, conversationId) {
166
+ const conversation = await this.findOne(conversationId);
167
+ if (!conversation)
168
+ return false;
169
+ if (!conversation.subscribers.includes(subscriberId))
170
+ return false;
171
+ return true;
172
+ }
173
+ async create(userId, employerId) {
174
+ const conversationId = uuid();
175
+ const newConversation = await pb.collection('conversations').create({
176
+ id: conversationId,
177
+ subscribers: [userId, employerId],
178
+ contents: [],
179
+ last_message: {},
180
+ });
181
+ return newConversation;
182
+ }
183
+ }
184
184
  //# sourceMappingURL=chat.js.map
@@ -1,3 +1,3 @@
1
- export * from './chat.js';
2
- export * from './pb.js';
1
+ export * from './chat.js';
2
+ export * from './pb.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1,16 +1,16 @@
1
- import PocketBase from 'pocketbase';
2
- import { ENV } from '../env.js';
3
- let _pb = {};
4
- if (!ENV.BICORE_IGNORE_POCKETBASE) {
5
- _pb = new PocketBase(ENV.PB_URL);
6
- _pb.autoCancellation(false);
7
- }
8
- export const pb = _pb;
9
- export const authenticatePocketbase = async () => {
10
- await _pb
11
- .collection('_superusers')
12
- .authWithPassword(ENV.PB_ADMIN_EMAIL, ENV.PB_ADMIN_PASSWORD, { autoRefreshThreshold: 30 * 60 });
13
- };
14
- if (!ENV.BICORE_IGNORE_POCKETBASE)
15
- authenticatePocketbase();
1
+ import PocketBase from 'pocketbase';
2
+ import { ENV } from '../env.js';
3
+ let _pb = {};
4
+ if (!ENV.BICORE_IGNORE_POCKETBASE) {
5
+ _pb = new PocketBase(ENV.PB_URL);
6
+ _pb.autoCancellation(false);
7
+ }
8
+ export const pb = _pb;
9
+ export const authenticatePocketbase = async () => {
10
+ await _pb
11
+ .collection('_superusers')
12
+ .authWithPassword(ENV.PB_ADMIN_EMAIL, ENV.PB_ADMIN_PASSWORD, { autoRefreshThreshold: 30 * 60 });
13
+ };
14
+ if (!ENV.BICORE_IGNORE_POCKETBASE)
15
+ authenticatePocketbase();
16
16
  //# sourceMappingURL=pb.js.map
@@ -1,67 +1,67 @@
1
- import { TransactionalEmailsApi } from '@getbrevo/brevo';
2
- import * as nodemailer from 'nodemailer';
3
- import { v4 } from 'uuid';
4
- import { ENV } from '../env.js';
5
- const SMTP_EMAIL = ENV.SMTP_EMAIL;
6
- const SMTP_PASSWORD = ENV.SMTP_PASSWORD;
7
- if (!SMTP_EMAIL || !SMTP_PASSWORD)
8
- throw Error('[ERROR:ENV]: Missing SMTP setup.');
9
- let transacApi = null;
10
- if (process.env.NODE_ENV !== 'development') {
11
- const BREVO_API_KEY = process.env.BREVO_API_KEY;
12
- if (!BREVO_API_KEY)
13
- throw Error('[ERROR:ENV]: Missing Brevo setup.');
14
- transacApi = new TransactionalEmailsApi();
15
- transacApi.setApiKey(0, BREVO_API_KEY);
16
- }
17
- const transporter = nodemailer.createTransport({
18
- service: 'Gmail',
19
- host: 'smtp.gmail.com',
20
- port: 465,
21
- secure: true,
22
- auth: {
23
- user: SMTP_EMAIL,
24
- pass: SMTP_PASSWORD,
25
- },
26
- messageId: `${v4()}${SMTP_EMAIL}`,
27
- });
28
- export const sendSingleEmail = async ({ sender, subject, recipient, content, alias = 'hello', }) => {
29
- if (process.env.NODE_ENV === 'development' || true) {
30
- return new Promise((resolve, reject) => {
31
- transporter.sendMail({
32
- from: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
33
- to: recipient,
34
- subject,
35
- html: content,
36
- }, (error, info) => {
37
- if (error) {
38
- console.error('[ERROR] Could not send email.');
39
- console.error('[-----] ' + error.message);
40
- }
41
- else {
42
- resolve({
43
- messageId: info.messageId,
44
- response: info.response,
45
- });
46
- console.warn('[LOG] Email sent to ' + recipient);
47
- }
48
- });
49
- });
50
- }
51
- else {
52
- const response = await transacApi?.sendTransacEmail({
53
- sender: {
54
- email: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
55
- },
56
- to: [{ email: recipient }],
57
- subject,
58
- htmlContent: content,
59
- });
60
- console.warn('[LOG] Email sent to ' + recipient);
61
- return {
62
- messageId: response?.body?.messageId,
63
- response: response?.response,
64
- };
65
- }
66
- };
1
+ import { TransactionalEmailsApi } from '@getbrevo/brevo';
2
+ import * as nodemailer from 'nodemailer';
3
+ import { v4 } from 'uuid';
4
+ import { ENV } from '../env.js';
5
+ const SMTP_EMAIL = ENV.SMTP_EMAIL;
6
+ const SMTP_PASSWORD = ENV.SMTP_PASSWORD;
7
+ if (!SMTP_EMAIL || !SMTP_PASSWORD)
8
+ throw Error('[ERROR:ENV]: Missing SMTP setup.');
9
+ let transacApi = null;
10
+ if (process.env.NODE_ENV !== 'development') {
11
+ const BREVO_API_KEY = process.env.BREVO_API_KEY;
12
+ if (!BREVO_API_KEY)
13
+ throw Error('[ERROR:ENV]: Missing Brevo setup.');
14
+ transacApi = new TransactionalEmailsApi();
15
+ transacApi.setApiKey(0, BREVO_API_KEY);
16
+ }
17
+ const transporter = nodemailer.createTransport({
18
+ service: 'Gmail',
19
+ host: 'smtp.gmail.com',
20
+ port: 465,
21
+ secure: true,
22
+ auth: {
23
+ user: SMTP_EMAIL,
24
+ pass: SMTP_PASSWORD,
25
+ },
26
+ messageId: `${v4()}${SMTP_EMAIL}`,
27
+ });
28
+ export const sendSingleEmail = async ({ sender, subject, recipient, content, alias = 'hello', }) => {
29
+ if (process.env.NODE_ENV === 'development' || true) {
30
+ return new Promise((resolve, reject) => {
31
+ transporter.sendMail({
32
+ from: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
33
+ to: recipient,
34
+ subject,
35
+ html: content,
36
+ }, (error, info) => {
37
+ if (error) {
38
+ console.error('[ERROR] Could not send email.');
39
+ console.error('[-----] ' + error.message);
40
+ }
41
+ else {
42
+ resolve({
43
+ messageId: info.messageId,
44
+ response: info.response,
45
+ });
46
+ console.warn('[LOG] Email sent to ' + recipient);
47
+ }
48
+ });
49
+ });
50
+ }
51
+ else {
52
+ const response = await transacApi?.sendTransacEmail({
53
+ sender: {
54
+ email: `"${sender ?? 'BetterInternship'}" <${alias}@betterinternship.com>`,
55
+ },
56
+ to: [{ email: recipient }],
57
+ subject,
58
+ htmlContent: content,
59
+ });
60
+ console.warn('[LOG] Email sent to ' + recipient);
61
+ return {
62
+ messageId: response?.body?.messageId,
63
+ response: response?.response,
64
+ };
65
+ }
66
+ };
67
67
  //# sourceMappingURL=email.js.map
@@ -1,2 +1,2 @@
1
- export * from './email.js';
1
+ export * from './email.js';
2
2
  //# sourceMappingURL=index.js.map
package/dist/lib/env.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as dotenv from "dotenv";
2
- dotenv.config();
3
- export const ENV = process.env;
1
+ import * as dotenv from "dotenv";
2
+ dotenv.config();
3
+ export const ENV = process.env;
4
4
  //# sourceMappingURL=env.js.map
@@ -1,30 +1,30 @@
1
- import { ZodType } from 'zod';
2
- import { BLOCK_TYPES, IFormField, IFormFieldPrefiller, IFormFieldValidator, IFormPhantomField, IFormSigningParty } from './form-metadata.js';
3
- type EnumValue = string | number;
4
- export declare const getSchemaClientType: (s: ZodType) => ClientFieldType;
5
- export type ClientFieldType = 'text' | 'number' | 'date' | 'dropdown' | 'checkbox' | 'textarea' | 'multiselect' | 'time' | 'signature';
6
- export type ClientField<SourceDomains extends any[]> = Omit<IFormField, 'x' | 'y' | 'w' | 'h' | 'page' | 'type' | 'validator' | 'prefiller' | 'align_h' | 'align_v'> & {
7
- type: ClientFieldType;
8
- signing_party_id?: string;
9
- validator: IFormFieldValidator | null;
10
- prefiller: IFormFieldPrefiller<SourceDomains> | null;
11
- options?: EnumValue[];
12
- coerce: (s: string) => string | number | boolean | Date | Array<string>;
13
- };
14
- export type ClientPhantomField<SourceDomains extends any[]> = Omit<IFormPhantomField, 'type' | 'validator' | 'prefiller'> & {
15
- type: ClientFieldType;
16
- signing_party_id?: string;
17
- validator: IFormFieldValidator | null;
18
- prefiller: IFormFieldPrefiller<SourceDomains> | null;
19
- options?: EnumValue[];
20
- coerce: (s: string) => string | number | boolean | Date | Array<string>;
21
- };
22
- export interface ClientBlock<SourceDomains extends any[]> {
23
- block_type: (typeof BLOCK_TYPES)[number];
24
- order: number;
25
- signing_party_id: IFormSigningParty['_id'];
26
- text_content?: string;
27
- field_schema?: ClientField<SourceDomains>;
28
- phantom_field_schema?: ClientPhantomField<SourceDomains>;
29
- }
30
- export {};
1
+ import { ZodType } from 'zod';
2
+ import { BLOCK_TYPES, IFormField, IFormFieldPrefiller, IFormFieldValidator, IFormPhantomField, IFormSigningParty } from './form-metadata.js';
3
+ type EnumValue = string | number;
4
+ export declare const getSchemaClientType: (s: ZodType) => ClientFieldType;
5
+ export type ClientFieldType = 'text' | 'number' | 'date' | 'dropdown' | 'checkbox' | 'textarea' | 'multiselect' | 'time' | 'signature';
6
+ export type ClientField<SourceDomains extends any[]> = Omit<IFormField, 'x' | 'y' | 'w' | 'h' | 'page' | 'type' | 'validator' | 'prefiller' | 'align_h' | 'align_v'> & {
7
+ type: ClientFieldType;
8
+ signing_party_id?: string;
9
+ validator: IFormFieldValidator | null;
10
+ prefiller: IFormFieldPrefiller<SourceDomains> | null;
11
+ options?: EnumValue[];
12
+ coerce: (s: string) => string | number | boolean | Date | Array<string>;
13
+ };
14
+ export type ClientPhantomField<SourceDomains extends any[]> = Omit<IFormPhantomField, 'type' | 'validator' | 'prefiller'> & {
15
+ type: ClientFieldType;
16
+ signing_party_id?: string;
17
+ validator: IFormFieldValidator | null;
18
+ prefiller: IFormFieldPrefiller<SourceDomains> | null;
19
+ options?: EnumValue[];
20
+ coerce: (s: string) => string | number | boolean | Date | Array<string>;
21
+ };
22
+ export interface ClientBlock<SourceDomains extends any[]> {
23
+ block_type: (typeof BLOCK_TYPES)[number];
24
+ order: number;
25
+ signing_party_id: IFormSigningParty['_id'];
26
+ text_content?: string;
27
+ field_schema?: ClientField<SourceDomains>;
28
+ phantom_field_schema?: ClientPhantomField<SourceDomains>;
29
+ }
30
+ export {};
@@ -1,21 +1,21 @@
1
- import z from 'zod';
2
- export const getSchemaClientType = (s) => {
3
- const infer = s.type;
4
- const desc = s.description;
5
- if (infer === 'date' || desc === 'date')
6
- return 'date';
7
- if (infer === 'number' || desc === 'number')
8
- return 'number';
9
- if (infer === 'enum' || desc === 'dropdown')
10
- return 'dropdown';
11
- if (infer === 'boolean' || desc === 'checkbox')
12
- return 'checkbox';
13
- if (s instanceof z.ZodArray && desc === 'multiselect')
14
- return 'multiselect';
15
- if (desc === 'textarea')
16
- return 'textarea';
17
- if (desc === 'time')
18
- return 'time';
19
- return 'text';
20
- };
1
+ import z from 'zod';
2
+ export const getSchemaClientType = (s) => {
3
+ const infer = s.type;
4
+ const desc = s.description;
5
+ if (infer === 'date' || desc === 'date')
6
+ return 'date';
7
+ if (infer === 'number' || desc === 'number')
8
+ return 'number';
9
+ if (infer === 'enum' || desc === 'dropdown')
10
+ return 'dropdown';
11
+ if (infer === 'boolean' || desc === 'checkbox')
12
+ return 'checkbox';
13
+ if (s instanceof z.ZodArray && desc === 'multiselect')
14
+ return 'multiselect';
15
+ if (desc === 'textarea')
16
+ return 'textarea';
17
+ if (desc === 'time')
18
+ return 'time';
19
+ return 'text';
20
+ };
21
21
  //# sourceMappingURL=fields.client.js.map