@betterinternship/core 2.2.0 → 2.2.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,11 +1,11 @@
1
- import * as amqp from 'amqplib';
2
- export declare const QueueName: (...args: string[]) => string;
3
- export declare const BrokerAPI: {
4
- assertQueue: (..._: any[]) => Promise<void>;
5
- sendToQueue: (..._: any[]) => Promise<void>;
6
- readFromQueue: (..._: any[]) => Promise<void>;
7
- } | {
8
- assertQueue: (queueId: string, options?: amqp.Options.AssertQueue) => Promise<amqp.Replies.AssertQueue>;
9
- sendToQueue: (queueId: string, content: any) => boolean;
10
- readFromQueue: <T>(queueId: string) => Promise<null>;
11
- };
1
+ import * as amqp from 'amqplib';
2
+ export declare const QueueName: (...args: string[]) => string;
3
+ export declare const BrokerAPI: {
4
+ assertQueue: (..._: any[]) => Promise<void>;
5
+ sendToQueue: (..._: any[]) => Promise<void>;
6
+ readFromQueue: (..._: any[]) => Promise<void>;
7
+ } | {
8
+ assertQueue: (queueId: string, options?: amqp.Options.AssertQueue) => Promise<amqp.Replies.AssertQueue>;
9
+ sendToQueue: (queueId: string, content: any) => boolean;
10
+ readFromQueue: <T>(queueId: string) => Promise<null>;
11
+ };
@@ -1,71 +1,71 @@
1
- import * as amqp from 'amqplib';
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 amqp.connect(RABBITMQ_URL);
21
- const channels = {
22
- asserter: await connection.createChannel(),
23
- reader: await connection.createChannel(),
24
- writer: await connection.createChannel(),
25
- };
26
- const assertQueue = async (queueId, options) => {
27
- const result = await channels.asserter.assertQueue(queueId, {
28
- durable: true,
29
- ...options,
30
- });
31
- console.log(`[BROKER] Queue "${queueId}" has been asserted.`);
32
- return result;
33
- };
34
- const sendToQueue = (queueId, content) => {
35
- const result = channels.writer.sendToQueue(queueId, Buffer.from(JSON.stringify(content)));
36
- if (result) {
37
- console.log(`[BROKER] Message sent to queue "${queueId}": ${JSON.stringify(content)}.`);
38
- }
39
- else {
40
- console.log(`[BROKER] Message could not sent to queue "${queueId}": ${JSON.stringify(content)}.`);
41
- }
42
- return result;
43
- };
44
- const readFromQueue = async (queueId) => {
45
- const resolveFromQueue = (message) => {
46
- channels.writer.ack(message);
47
- console.log(`[BROKER] Message "${message.properties.messageId}" resolved from queue "${queueId}".`);
48
- };
49
- const rejectFromQueue = (message) => {
50
- channels.writer.nack(message);
51
- console.log(`[BROKER] Message "${message.properties.messageId}" rejected from queue "${queueId}".`);
52
- };
53
- let result = null;
54
- await channels.reader.consume(queueId, (message) => {
55
- const content = message?.content?.toString?.();
56
- result = {
57
- content: content ? JSON.parse(content) : null,
58
- resolve: () => message && resolveFromQueue(message),
59
- reject: () => message && rejectFromQueue(message),
60
- };
61
- return message ? result : null;
62
- });
63
- return result;
64
- };
65
- return {
66
- assertQueue,
67
- sendToQueue,
68
- readFromQueue,
69
- };
70
- })();
1
+ import * as amqp from 'amqplib';
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 amqp.connect(RABBITMQ_URL);
21
+ const channels = {
22
+ asserter: await connection.createChannel(),
23
+ reader: await connection.createChannel(),
24
+ writer: await connection.createChannel(),
25
+ };
26
+ const assertQueue = async (queueId, options) => {
27
+ const result = await channels.asserter.assertQueue(queueId, {
28
+ durable: true,
29
+ ...options,
30
+ });
31
+ console.log(`[BROKER] Queue "${queueId}" has been asserted.`);
32
+ return result;
33
+ };
34
+ const sendToQueue = (queueId, content) => {
35
+ const result = channels.writer.sendToQueue(queueId, Buffer.from(JSON.stringify(content)));
36
+ if (result) {
37
+ console.log(`[BROKER] Message sent to queue "${queueId}": ${JSON.stringify(content)}.`);
38
+ }
39
+ else {
40
+ console.log(`[BROKER] Message could not sent to queue "${queueId}": ${JSON.stringify(content)}.`);
41
+ }
42
+ return result;
43
+ };
44
+ const readFromQueue = async (queueId) => {
45
+ const resolveFromQueue = (message) => {
46
+ channels.writer.ack(message);
47
+ console.log(`[BROKER] Message "${message.properties.messageId}" resolved from queue "${queueId}".`);
48
+ };
49
+ const rejectFromQueue = (message) => {
50
+ channels.writer.nack(message);
51
+ console.log(`[BROKER] Message "${message.properties.messageId}" rejected from queue "${queueId}".`);
52
+ };
53
+ let result = null;
54
+ await channels.reader.consume(queueId, (message) => {
55
+ const content = message?.content?.toString?.();
56
+ result = {
57
+ content: content ? JSON.parse(content) : null,
58
+ resolve: () => message && resolveFromQueue(message),
59
+ reject: () => message && rejectFromQueue(message),
60
+ };
61
+ return message ? result : null;
62
+ });
63
+ return result;
64
+ };
65
+ return {
66
+ assertQueue,
67
+ sendToQueue,
68
+ readFromQueue,
69
+ };
70
+ })();
71
71
  //# sourceMappingURL=broker.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,127 +1,127 @@
1
- import { ZodType } from 'zod';
2
- import { ClientBlock, ClientField, ClientPhantomField } from './fields.client';
3
- import { ServerField } from './fields.server';
4
- export type FormValues = Record<string, string>;
5
- export type FormErrors = Record<string, string>;
6
- export declare const SCHEMA_VERSION = 1;
7
- export declare const FIELD_TYPES: string[];
8
- export declare const BLOCK_TYPES: string[];
9
- export declare const ALIGN_H: string[];
10
- export declare const ALIGN_V: string[];
11
- export declare const SOURCES: string[];
12
- export interface IFormMetadata {
13
- name: string;
14
- label: string;
15
- schema_version: number;
16
- schema: IForm;
17
- signing_parties: IFormSigningParty[];
18
- subscribers?: IFormSubscriber[];
19
- }
20
- export type IFormSubscriber = {
21
- email: string;
22
- };
23
- export interface IFormSignatory {
24
- name?: string;
25
- email: string;
26
- title?: string;
27
- honorific?: string;
28
- }
29
- export interface IFormSigningParty {
30
- _id: string;
31
- order: number;
32
- signatory_title: string;
33
- signatory_account?: IFormSignatory;
34
- signatory_source?: {
35
- _id: string;
36
- label: string;
37
- tooltip_label: string;
38
- };
39
- signed?: boolean;
40
- }
41
- export interface IFormSignee {
42
- name: string;
43
- sourceEmail: string;
44
- title?: string;
45
- honorific?: string;
46
- signedDate?: number;
47
- }
48
- export interface IForm {
49
- blocks: IFormBlock[];
50
- }
51
- export interface IFormBlock {
52
- _id: string;
53
- block_type: (typeof BLOCK_TYPES)[number];
54
- order: number;
55
- signing_party_id: IFormSigningParty['_id'];
56
- text_content?: string;
57
- field_schema?: IFormField;
58
- phantom_field_schema?: IFormPhantomField;
59
- }
60
- export interface IFormField {
61
- field: string;
62
- type: 'text' | 'signature' | 'image';
63
- x: number;
64
- y: number;
65
- w: number;
66
- h: number;
67
- page: number;
68
- align_h?: (typeof ALIGN_H)[number];
69
- align_v?: (typeof ALIGN_V)[number];
70
- label: string;
71
- tooltip_label: string;
72
- shared: boolean;
73
- source: (typeof SOURCES)[number];
74
- prefiller?: string;
75
- validator?: string;
76
- size?: number;
77
- wrap?: boolean;
78
- }
79
- export interface IFormPhantomField {
80
- field: string;
81
- type: 'text' | 'signature' | 'image';
82
- label: string;
83
- tooltip_label: string;
84
- shared: boolean;
85
- source: (typeof SOURCES)[number];
86
- prefiller?: string;
87
- validator?: string;
88
- }
89
- export interface IFormParameters {
90
- [key: string]: string | ZodType;
91
- }
92
- export type IFormSourceDomains<SourceDomains extends any[]> = Record<string, SourceDomains[number]>;
93
- export type IFormFieldValidator = ZodType;
94
- export type IFormFieldPrefiller<SourceDomains extends any[]> = (sourceDomains: IFormSourceDomains<SourceDomains>) => string;
95
- export declare class FormMetadata<SourceDomains extends any[]> {
96
- private readonly formMetadata;
97
- private readonly blocks;
98
- constructor(formMetadata: IFormMetadata);
99
- getBlocksForClientService(signingPartyId?: string): ClientBlock<SourceDomains>[];
100
- getSigningPartyBlocks(signingPartyId: string): ClientBlock<SourceDomains>[];
101
- getSigningPartyFields(signingPartyId: string): (ClientField<SourceDomains> | ClientPhantomField<SourceDomains>)[];
102
- static getSigningPartyValues(signingParties: IFormSigningParty[], values: FormValues): Record<string, IFormSignatory>;
103
- private getFields;
104
- private getField;
105
- private getPhantomFields;
106
- private getPhantomField;
107
- encodeAsJSON(): string;
108
- static decodeFromJSON<SourceDomains extends any[]>(json: string): FormMetadata<SourceDomains>;
109
- getLabel(): string;
110
- private getFieldForClientService;
111
- getFieldsForClientService(signingPartyId?: string, sourceDomains?: IFormSourceDomains<SourceDomains>, derivationBase?: IFormParameters): (ClientField<SourceDomains> | ClientPhantomField<SourceDomains>)[];
112
- getSignatureFieldsForClientService(signingPartyId: string): (ClientField<SourceDomains> | ClientPhantomField<SourceDomains>)[];
113
- getSignatureValueForSigningParty(values: FormValues, signingPartyId: string): string;
114
- setSignatureValueForSigningParty(values: FormValues, signatureString: string, signingPartyId: string): FormValues;
115
- getFieldsForEditorService(): IFormField[];
116
- getPhantomFieldsForEditorService(): IFormPhantomField[];
117
- getBlocksForEditorService(): IFormBlock[];
118
- getFieldsForSigningService(): ServerField[];
119
- inferParams(): string[];
120
- private parseValidator;
121
- private parsePrefiller;
122
- private enumerateParams;
123
- private populateParams;
124
- getSubscribers(): IFormSubscriber[];
125
- getSigningParties(): IFormSigningParty[];
126
- mayInvolveEsign(): boolean;
127
- }
1
+ import { ZodType } from 'zod';
2
+ import { ClientBlock, ClientField, ClientPhantomField } from './fields.client.js';
3
+ import { ServerField } from './fields.server.js';
4
+ export type FormValues = Record<string, string>;
5
+ export type FormErrors = Record<string, string>;
6
+ export declare const SCHEMA_VERSION = 1;
7
+ export declare const FIELD_TYPES: string[];
8
+ export declare const BLOCK_TYPES: string[];
9
+ export declare const ALIGN_H: string[];
10
+ export declare const ALIGN_V: string[];
11
+ export declare const SOURCES: string[];
12
+ export interface IFormMetadata {
13
+ name: string;
14
+ label: string;
15
+ schema_version: number;
16
+ schema: IForm;
17
+ signing_parties: IFormSigningParty[];
18
+ subscribers?: IFormSubscriber[];
19
+ }
20
+ export type IFormSubscriber = {
21
+ email: string;
22
+ };
23
+ export interface IFormSignatory {
24
+ name?: string;
25
+ email: string;
26
+ title?: string;
27
+ honorific?: string;
28
+ }
29
+ export interface IFormSigningParty {
30
+ _id: string;
31
+ order: number;
32
+ signatory_title: string;
33
+ signatory_account?: IFormSignatory;
34
+ signatory_source?: {
35
+ _id: string;
36
+ label: string;
37
+ tooltip_label: string;
38
+ };
39
+ signed?: boolean;
40
+ }
41
+ export interface IFormSignee {
42
+ name: string;
43
+ sourceEmail: string;
44
+ title?: string;
45
+ honorific?: string;
46
+ signedDate?: number;
47
+ }
48
+ export interface IForm {
49
+ blocks: IFormBlock[];
50
+ }
51
+ export interface IFormBlock {
52
+ _id: string;
53
+ block_type: (typeof BLOCK_TYPES)[number];
54
+ order: number;
55
+ signing_party_id: IFormSigningParty['_id'];
56
+ text_content?: string;
57
+ field_schema?: IFormField;
58
+ phantom_field_schema?: IFormPhantomField;
59
+ }
60
+ export interface IFormField {
61
+ field: string;
62
+ type: 'text' | 'signature' | 'image';
63
+ x: number;
64
+ y: number;
65
+ w: number;
66
+ h: number;
67
+ page: number;
68
+ align_h?: (typeof ALIGN_H)[number];
69
+ align_v?: (typeof ALIGN_V)[number];
70
+ label: string;
71
+ tooltip_label: string;
72
+ shared: boolean;
73
+ source: (typeof SOURCES)[number];
74
+ prefiller?: string;
75
+ validator?: string;
76
+ size?: number;
77
+ wrap?: boolean;
78
+ }
79
+ export interface IFormPhantomField {
80
+ field: string;
81
+ type: 'text' | 'signature' | 'image';
82
+ label: string;
83
+ tooltip_label: string;
84
+ shared: boolean;
85
+ source: (typeof SOURCES)[number];
86
+ prefiller?: string;
87
+ validator?: string;
88
+ }
89
+ export interface IFormParameters {
90
+ [key: string]: string | ZodType;
91
+ }
92
+ export type IFormSourceDomains<SourceDomains extends any[]> = Record<string, SourceDomains[number]>;
93
+ export type IFormFieldValidator = ZodType;
94
+ export type IFormFieldPrefiller<SourceDomains extends any[]> = (sourceDomains: IFormSourceDomains<SourceDomains>) => string;
95
+ export declare class FormMetadata<SourceDomains extends any[]> {
96
+ private readonly formMetadata;
97
+ private readonly blocks;
98
+ constructor(formMetadata: IFormMetadata);
99
+ getBlocksForClientService(signingPartyId?: string): ClientBlock<SourceDomains>[];
100
+ getSigningPartyBlocks(signingPartyId: string): ClientBlock<SourceDomains>[];
101
+ getSigningPartyFields(signingPartyId: string): (ClientField<SourceDomains> | ClientPhantomField<SourceDomains>)[];
102
+ static getSigningPartyValues(signingParties: IFormSigningParty[], values: FormValues): Record<string, IFormSignatory>;
103
+ private getFields;
104
+ private getField;
105
+ private getPhantomFields;
106
+ private getPhantomField;
107
+ encodeAsJSON(): string;
108
+ static decodeFromJSON<SourceDomains extends any[]>(json: string): FormMetadata<SourceDomains>;
109
+ getLabel(): string;
110
+ private getFieldForClientService;
111
+ getFieldsForClientService(signingPartyId?: string, sourceDomains?: IFormSourceDomains<SourceDomains>, derivationBase?: IFormParameters): (ClientField<SourceDomains> | ClientPhantomField<SourceDomains>)[];
112
+ getSignatureFieldsForClientService(signingPartyId: string): (ClientField<SourceDomains> | ClientPhantomField<SourceDomains>)[];
113
+ getSignatureValueForSigningParty(values: FormValues, signingPartyId: string): string;
114
+ setSignatureValueForSigningParty(values: FormValues, signatureString: string, signingPartyId: string): FormValues;
115
+ getFieldsForEditorService(): IFormField[];
116
+ getPhantomFieldsForEditorService(): IFormPhantomField[];
117
+ getBlocksForEditorService(): IFormBlock[];
118
+ getFieldsForSigningService(): ServerField[];
119
+ inferParams(): string[];
120
+ private parseValidator;
121
+ private parsePrefiller;
122
+ private enumerateParams;
123
+ private populateParams;
124
+ getSubscribers(): IFormSubscriber[];
125
+ getSigningParties(): IFormSigningParty[];
126
+ mayInvolveEsign(): boolean;
127
+ }