@betterinternship/core 2.1.1 → 2.1.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './lib/chat/index.js';
2
- export * from './lib/env.js';
3
- export * from './lib/broker/index.js';
4
- export * from './lib/email/index.js';
5
- export * from './lib/forms/index.js';
1
+ export * from './lib/chat/index.js';
2
+ export * from './lib/env.js';
3
+ export * from './lib/broker/index.js';
4
+ export * from './lib/email/index.js';
5
+ export * from './lib/forms/index.js';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export * from './lib/chat/index.js';
2
- export * from './lib/env.js';
3
- export * from './lib/broker/index.js';
4
- export * from './lib/email/index.js';
5
- export * from './lib/forms/index.js';
1
+ export * from './lib/chat/index.js';
2
+ export * from './lib/env.js';
3
+ export * from './lib/broker/index.js';
4
+ export * from './lib/email/index.js';
5
+ export * from './lib/forms/index.js';
6
6
  //# sourceMappingURL=index.js.map
@@ -1,78 +1,78 @@
1
- import * as amqp from 'amqplib/callback_api';
2
- import { ENV } from '../env.js';
3
- const RABBITMQ_URL = ENV.RABBITMQ_URL;
4
- if (!RABBITMQ_URL && ENV.RABBITMQ_ENABLED)
5
- throw new Error('[ERROR:ENV] Missing RabbitMQ configuration.');
6
- export const QueueName = (...args) => {
7
- if (ENV.ENVIRONMENT === 'production')
8
- return args.join('.');
9
- else
10
- return ['dev', ...args].join('.');
11
- };
12
- export const BrokerAPI = await (async () => {
13
- if (!RABBITMQ_URL) {
14
- return {
15
- assertQueue: async (..._) => { },
16
- sendToQueue: async (..._) => { },
17
- readFromQueue: async (..._) => { },
18
- };
19
- }
20
- const connection = await new Promise((resolve) => {
21
- amqp.connect(RABBITMQ_URL, (err, connection) => {
22
- if (err)
23
- throw err;
24
- resolve(connection);
25
- });
26
- });
27
- const createChannel = async () => {
28
- return new Promise((resolve) => {
29
- connection.createChannel((err, channel) => {
30
- if (err)
31
- throw err;
32
- resolve(channel);
33
- });
34
- });
35
- };
36
- const channels = {
37
- asserter: await createChannel(),
38
- reader: await createChannel(),
39
- writer: await createChannel(),
40
- };
41
- const assertQueue = (queueId, options) => {
42
- channels.asserter.assertQueue(queueId, { durable: true, ...options });
43
- console.log(`[BROKER] Queue "${queueId}" has been asserted.`);
44
- };
45
- const sendToQueue = (queueId, content) => {
46
- channels.writer.sendToQueue(queueId, Buffer.from(JSON.stringify(content)));
47
- console.log(`[BROKER] Message sent to queue "${queueId}": ${JSON.stringify(content)}.`);
48
- };
49
- const readFromQueue = (queueId) => {
50
- const resolveFromQueue = (message) => {
51
- channels.writer.ack(message);
52
- console.log(`[BROKER] Message "${message.properties.messageId}" resolved from queue "${queueId}".`);
53
- };
54
- const rejectFromQueue = (message) => {
55
- channels.writer.nack(message);
56
- console.log(`[BROKER] Message "${message.properties.messageId}" rejected from queue "${queueId}".`);
57
- };
58
- return new Promise((resolve) => channels.reader.consume(queueId, (message) => {
59
- const result = {
60
- content: message?.content.toJSON(),
61
- resolve: () => message && resolveFromQueue(message),
62
- reject: () => message && rejectFromQueue(message),
63
- };
64
- if (message) {
65
- resolve(result);
66
- }
67
- else {
68
- resolve(null);
69
- }
70
- }));
71
- };
72
- return {
73
- assertQueue,
74
- sendToQueue,
75
- readFromQueue,
76
- };
77
- })();
1
+ import * as amqp from 'amqplib/callback_api';
2
+ import { ENV } from '../env.js';
3
+ const RABBITMQ_URL = ENV.RABBITMQ_URL;
4
+ if (!RABBITMQ_URL && ENV.RABBITMQ_ENABLED)
5
+ throw new Error('[ERROR:ENV] Missing RabbitMQ configuration.');
6
+ export const QueueName = (...args) => {
7
+ if (ENV.ENVIRONMENT === 'production')
8
+ return args.join('.');
9
+ else
10
+ return ['dev', ...args].join('.');
11
+ };
12
+ export const BrokerAPI = await (async () => {
13
+ if (!RABBITMQ_URL) {
14
+ return {
15
+ assertQueue: async (..._) => { },
16
+ sendToQueue: async (..._) => { },
17
+ readFromQueue: async (..._) => { },
18
+ };
19
+ }
20
+ const connection = await new Promise((resolve) => {
21
+ amqp.connect(RABBITMQ_URL, (err, connection) => {
22
+ if (err)
23
+ throw err;
24
+ resolve(connection);
25
+ });
26
+ });
27
+ const createChannel = async () => {
28
+ return new Promise((resolve) => {
29
+ connection.createChannel((err, channel) => {
30
+ if (err)
31
+ throw err;
32
+ resolve(channel);
33
+ });
34
+ });
35
+ };
36
+ const channels = {
37
+ asserter: await createChannel(),
38
+ reader: await createChannel(),
39
+ writer: await createChannel(),
40
+ };
41
+ const assertQueue = (queueId, options) => {
42
+ channels.asserter.assertQueue(queueId, { durable: true, ...options });
43
+ console.log(`[BROKER] Queue "${queueId}" has been asserted.`);
44
+ };
45
+ const sendToQueue = (queueId, content) => {
46
+ channels.writer.sendToQueue(queueId, Buffer.from(JSON.stringify(content)));
47
+ console.log(`[BROKER] Message sent to queue "${queueId}": ${JSON.stringify(content)}.`);
48
+ };
49
+ const readFromQueue = (queueId) => {
50
+ const resolveFromQueue = (message) => {
51
+ channels.writer.ack(message);
52
+ console.log(`[BROKER] Message "${message.properties.messageId}" resolved from queue "${queueId}".`);
53
+ };
54
+ const rejectFromQueue = (message) => {
55
+ channels.writer.nack(message);
56
+ console.log(`[BROKER] Message "${message.properties.messageId}" rejected from queue "${queueId}".`);
57
+ };
58
+ return new Promise((resolve) => channels.reader.consume(queueId, (message) => {
59
+ const result = {
60
+ content: message?.content.toJSON(),
61
+ resolve: () => message && resolveFromQueue(message),
62
+ reject: () => message && rejectFromQueue(message),
63
+ };
64
+ if (message) {
65
+ resolve(result);
66
+ }
67
+ else {
68
+ resolve(null);
69
+ }
70
+ }));
71
+ };
72
+ return {
73
+ assertQueue,
74
+ sendToQueue,
75
+ readFromQueue,
76
+ };
77
+ })();
78
78
  //# sourceMappingURL=broker.js.map
@@ -1 +1 @@
1
- export * from './broker.js';
1
+ export * from './broker.js';
@@ -1,2 +1,2 @@
1
- export * from './broker.js';
1
+ export * from './broker.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1,51 +1,51 @@
1
- import { RecordModel } from 'pocketbase';
2
- export interface Message {
3
- message: string;
4
- sender_id: string;
5
- timestamp: number;
6
- digested?: boolean;
7
- }
8
- export interface Consumer extends RecordModel {
9
- email: string;
10
- last_reads: {
11
- [conversationId: string]: Message;
12
- };
13
- last_unreads: {
14
- [conversationId: string]: Message;
15
- };
16
- conversations: string[];
17
- }
18
- export interface Conversation extends RecordModel {
19
- id: string;
20
- subscribers: string[];
21
- contents: Message[];
22
- last_message: Message;
23
- }
24
- export declare class ConsumerService {
25
- findOne(id: string): Promise<Consumer>;
26
- findAll(): Promise<Consumer[]>;
27
- register(id: string, email: string): Promise<Consumer>;
28
- setLastRead(id: string, conversationId: string, message: Message): Promise<RecordModel>;
29
- authenticateAs(id: string): Promise<{
30
- token: string;
31
- user: import("pocketbase").AuthRecord;
32
- }>;
33
- }
34
- export declare class MessageService {
35
- private readonly consumerService;
36
- private readonly conversationService;
37
- private updateConversationUnread;
38
- send(senderId: string, conversationId: string, messageContent: string): Promise<Message>;
39
- read(consumerId: string, conversationId: string): Promise<Message>;
40
- digest(consumerId: string, conversationId: string): Promise<Message>;
41
- }
42
- export declare class ConversationService {
43
- consumerService: ConsumerService;
44
- findOne(id: string): Promise<Conversation>;
45
- appendMessage(conversationId: string, message: Message): Promise<Conversation>;
46
- subscribe(subscriberId: string, conversationId: string): Promise<Conversation>;
47
- getSubscriptions(subscriberId: any): Promise<Conversation[]>;
48
- findExisting(userId: string, employerId: string): Promise<Conversation>;
49
- checkIfSubscribed(subscriberId: string, conversationId: string): Promise<boolean>;
50
- create(userId: string, employerId: string): Promise<Conversation>;
51
- }
1
+ import { RecordModel } from 'pocketbase';
2
+ export interface Message {
3
+ message: string;
4
+ sender_id: string;
5
+ timestamp: number;
6
+ digested?: boolean;
7
+ }
8
+ export interface Consumer extends RecordModel {
9
+ email: string;
10
+ last_reads: {
11
+ [conversationId: string]: Message;
12
+ };
13
+ last_unreads: {
14
+ [conversationId: string]: Message;
15
+ };
16
+ conversations: string[];
17
+ }
18
+ export interface Conversation extends RecordModel {
19
+ id: string;
20
+ subscribers: string[];
21
+ contents: Message[];
22
+ last_message: Message;
23
+ }
24
+ export declare class ConsumerService {
25
+ findOne(id: string): Promise<Consumer>;
26
+ findAll(): Promise<Consumer[]>;
27
+ register(id: string, email: string): Promise<Consumer>;
28
+ setLastRead(id: string, conversationId: string, message: Message): Promise<RecordModel>;
29
+ authenticateAs(id: string): Promise<{
30
+ token: string;
31
+ user: import("pocketbase").AuthRecord;
32
+ }>;
33
+ }
34
+ export declare class MessageService {
35
+ private readonly consumerService;
36
+ private readonly conversationService;
37
+ private updateConversationUnread;
38
+ send(senderId: string, conversationId: string, messageContent: string): Promise<Message>;
39
+ read(consumerId: string, conversationId: string): Promise<Message>;
40
+ digest(consumerId: string, conversationId: string): Promise<Message>;
41
+ }
42
+ export declare class ConversationService {
43
+ consumerService: ConsumerService;
44
+ findOne(id: string): Promise<Conversation>;
45
+ appendMessage(conversationId: string, message: Message): Promise<Conversation>;
46
+ subscribe(subscriberId: string, conversationId: string): Promise<Conversation>;
47
+ getSubscriptions(subscriberId: any): Promise<Conversation[]>;
48
+ findExisting(userId: string, employerId: string): Promise<Conversation>;
49
+ checkIfSubscribed(subscriberId: string, conversationId: string): Promise<boolean>;
50
+ create(userId: string, employerId: string): Promise<Conversation>;
51
+ }
@@ -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,2 +1,2 @@
1
- export * from './chat.js';
2
- export * from './pb.js';
1
+ export * from './chat.js';
2
+ export * from './pb.js';
@@ -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,3 +1,3 @@
1
- import PocketBase from 'pocketbase';
2
- export declare const pb: PocketBase;
3
- export declare const authenticatePocketbase: () => Promise<void>;
1
+ import PocketBase from 'pocketbase';
2
+ export declare const pb: PocketBase;
3
+ export declare const authenticatePocketbase: () => Promise<void>;
@@ -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 +1 @@
1
- export * from './email.js';
1
+ export * from './email.js';
@@ -1,2 +1,2 @@
1
- export * from './email.js';
1
+ export * from './email.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1,29 +1,29 @@
1
- import { ZodType } from 'zod';
2
- import { BLOCK_TYPES, IFormField, IFormFieldPrefiller, IFormFieldValidator, IFormPhantomField, IFormSigningParty } from './form-metadata.js';
3
- import { EnumValue } from 'zod/v4/core/util.cjs';
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
- }
1
+ import { ZodType } from 'zod';
2
+ import { BLOCK_TYPES, IFormField, IFormFieldPrefiller, IFormFieldValidator, IFormPhantomField, IFormSigningParty } from './form-metadata.js';
3
+ import { EnumValue } from 'zod/v4/core/util.cjs';
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
+ }
@@ -1,3 +1,3 @@
1
- export * from './form-metadata.js';
2
- export * from './fields.client.js';
3
- export * from './fields.server.js';
1
+ export * from './form-metadata.js';
2
+ export * from './fields.client.js';
3
+ export * from './fields.server.js';
@@ -1,4 +1,4 @@
1
- export * from './form-metadata.js';
2
- export * from './fields.client.js';
3
- export * from './fields.server.js';
1
+ export * from './form-metadata.js';
2
+ export * from './fields.client.js';
3
+ export * from './fields.server.js';
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterinternship/core",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Core library of BetterInternship services.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",