@betterinternship/core 2.1.0 → 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 +5 -5
- package/dist/index.js +5 -5
- package/dist/lib/broker/broker.js +77 -77
- package/dist/lib/broker/index.d.ts +1 -1
- package/dist/lib/broker/index.js +1 -1
- package/dist/lib/broker/index.js.map +1 -1
- package/dist/lib/chat/chat.d.ts +51 -51
- package/dist/lib/chat/chat.js +183 -183
- package/dist/lib/chat/index.d.ts +2 -2
- package/dist/lib/chat/index.js +2 -2
- package/dist/lib/chat/index.js.map +1 -1
- package/dist/lib/chat/pb.d.ts +3 -3
- package/dist/lib/chat/pb.js +15 -15
- package/dist/lib/email/email.js +66 -66
- package/dist/lib/email/index.d.ts +1 -1
- package/dist/lib/email/index.js +1 -1
- package/dist/lib/email/index.js.map +1 -1
- package/dist/lib/forms/fields.client.d.ts +29 -29
- package/dist/lib/forms/index.d.ts +3 -3
- package/dist/lib/forms/index.js +3 -3
- package/dist/lib/forms/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
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';
|
|
1
|
+
export * from './broker.js';
|
package/dist/lib/broker/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './broker';
|
|
1
|
+
export * from './broker.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/broker/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/broker/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/dist/lib/chat/chat.d.ts
CHANGED
|
@@ -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
|
+
}
|