core-services-sdk 1.3.52 → 1.3.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-services-sdk",
3
- "version": "1.3.52",
3
+ "version": "1.3.53",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "types": "types/index.d.ts",
@@ -2,30 +2,39 @@ export function generateId(): string
2
2
  export function generatePrefixedId(prefix: string): string
3
3
  export function generateUserId(): string
4
4
  export function generateTenantId(): string
5
+ export function generateSessionId(): string
6
+ export function generateOnboardingId(): string
5
7
  export function generatePermissionId(): string
6
- export function generateCorrelationId(): string
7
- export function generateVerificationId(): string
8
+ export function generateRoleId(): string
8
9
  export function generateRolePermissionsId(): string
9
- export function generateOnboardingId(): string
10
- export function generateSessionId(): string
10
+ export function generateVerificationId(): string
11
+ export function generateAssetId(): string
12
+ export function generateAssetUploadId(): string
11
13
  export function generateFileId(): string
14
+ export function generateSupplierId(): string
15
+ export function generateInvoiceId(): string
16
+ export function generateInvoiceItemId(): string
17
+ export function generateInvoiceCorrectionId(): string
18
+ export function generateDocumentDataId(): string
19
+ export function generateBotFlowId(): string
20
+ export function generateCorrelationId(): string
12
21
  export function generateEventId(): string
13
22
  export function generateJobId(): string
14
23
  export function generateTaskId(): string
15
24
  export function generateQueueId(): string
16
25
  export function generateMessageId(): string
26
+ export function generateEmailId(): string
27
+ export function generateIncomingEmailId(): string
28
+ export function generateImId(): string
17
29
  export function generateNotificationId(): string
18
- export function generateLogId(): string
19
30
  export function generateAuditId(): string
20
- export function generateConfigId(): string
21
- export function generateKeyId(): string
31
+ export function generateLogId(): string
22
32
  export function generateMetricId(): string
23
- export function generateTagId(): string
33
+ export function generateKeyId(): string
24
34
  export function generatePolicyId(): string
25
35
  export function generateProfileId(): string
26
36
  export function generateDeviceId(): string
27
37
  export function generateAlertId(): string
28
38
  export function generateResourceId(): string
29
- export function generateIncomingEmailId(): string
30
- export function generateEmailId(): string
31
- export function generateImId(): string
39
+ export function generateTagId(): string
40
+ export function generateConfigId(): string
@@ -1,76 +1,62 @@
1
1
  /**
2
2
  * Mapping of entity types to their unique ID prefixes.
3
3
  *
4
- * These prefixes are prepended to ULIDs to create consistent and identifiable IDs across the system.
5
- * For example: 'usr_01HZY3M7K4FJ9A8Q4Y1ZB5NX3T'
4
+ * Prefixes are prepended to ULIDs to create readable,
5
+ * sortable, and easily identifiable IDs across the system.
6
+ *
7
+ * Example:
8
+ * ast_01HZY3M7K4FJ9A8Q4Y1ZB5NX3T
6
9
  */
7
10
  export type ID_PREFIXES = string
8
11
  /**
9
12
  * Mapping of entity types to their unique ID prefixes.
10
13
  *
11
- * These prefixes are prepended to ULIDs to create consistent and identifiable IDs across the system.
12
- * For example: 'usr_01HZY3M7K4FJ9A8Q4Y1ZB5NX3T'
14
+ * Prefixes are prepended to ULIDs to create readable,
15
+ * sortable, and easily identifiable IDs across the system.
16
+ *
17
+ * Example:
18
+ * ast_01HZY3M7K4FJ9A8Q4Y1ZB5NX3T
13
19
  *
14
20
  * @readonly
15
21
  * @enum {string}
16
22
  */
17
23
  export const ID_PREFIXES: Readonly<{
18
- /** User entity ID prefix */
19
24
  USER: 'usr'
20
- /** Tenant entity ID prefix */
21
25
  TENANT: 'tnt'
22
- /** Permission entity ID prefix */
26
+ SESSION: 'sess'
27
+ ONBOARDING: 'onb'
28
+ ROLE: 'role'
23
29
  PERMISSION: 'prm'
24
- /** Correlation ID prefix (e.g., for tracing requests) */
25
- CORRELATION: 'crln'
26
- /** Verification entity ID prefix (e.g., email/phone code) */
30
+ ROLE_PERMISSION: 'rprm'
27
31
  VERIFICATION: 'vrf'
28
- /** Role-permissions mapping ID prefix */
29
- ROLE_PERMISSIONS: 'role'
30
- /** Onboarding mapping ID prefix */
31
- ONBOARDING: 'onb'
32
- /** Session mapping ID prefix */
33
- SESSION: 'sess'
34
- /** File mapping ID prefix */
32
+ POLICY: 'plc'
33
+ PROFILE: 'prf'
34
+ DEVICE: 'dev'
35
+ ASSET: 'ast'
36
+ ASSET_UPLOAD: 'aupl'
35
37
  FILE: 'fil'
36
- /** Event entity ID prefix */
38
+ SUPPLIER: 'sup'
39
+ INVOICE: 'inv'
40
+ INVOICE_ITEM: 'invi'
41
+ INVOICE_CORRECTION: 'invc'
42
+ DOCUMENT_DATA: 'docd'
43
+ CORRELATION: 'crln'
37
44
  EVENT: 'evt'
38
- /** Job entity ID prefix */
39
45
  JOB: 'job'
40
- /** Task entity ID prefix */
41
46
  TASK: 'task'
42
- /** Queue entity ID prefix */
43
47
  QUEUE: 'que'
44
- /** Message entity ID prefix */
45
48
  MESSAGE: 'msg'
46
- /** Notification entity ID prefix */
47
49
  NOTIFICATION: 'ntf'
48
- /** Log entity ID prefix */
49
- LOG: 'log'
50
- /** Audit entity ID prefix */
50
+ EMAIL: 'eml'
51
+ INCOMING_EMAIL: 'ieml'
52
+ IM: 'im'
51
53
  AUDIT: 'adt'
52
- /** Config entity ID prefix */
53
- CONFIG: 'cfg'
54
- /** Key entity ID prefix */
55
- KEY: 'key'
56
- /** Metric entity ID prefix */
54
+ LOG: 'log'
57
55
  METRIC: 'met'
58
- /** Tag entity ID prefix */
59
56
  TAG: 'tag'
60
- /** Policy entity ID prefix */
61
- POLICY: 'plc'
62
- /** Profile entity ID prefix */
63
- PROFILE: 'prf'
64
- /** Device entity ID prefix */
65
- DEVICE: 'dev'
66
- /** Alert entity ID prefix */
67
- ALERT: 'alr'
68
- /** Resource entity ID prefix */
57
+ CONFIG: 'cfg'
58
+ KEY: 'key'
69
59
  RESOURCE: 'res'
70
- /** Incoming email ID prefix */
71
- INCOMING_EMAIL: 'ieml'
72
- /** Email ID prefix */
73
- EMAIL: 'eml'
74
- /** Instant Message ID prefix */
75
- IM: 'im'
60
+ ALERT: 'alr'
61
+ BOT_FLOW: 'botf'
76
62
  }>
package/types/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export * from './rabbit-mq/index.js'
10
10
  export * from './templates/index.js'
11
11
  export * from './util/index.js'
12
12
  export * from './instant-messages/index.js'
13
+ export * from './postgresql/index.js'
@@ -0,0 +1 @@
1
+ export function connectToPg(connection: object | string): import('knex').Knex
@@ -0,0 +1,3 @@
1
+ export * from './connect-to-pg.js'
2
+ export * from './validate-schema.js'
3
+ export * from './start-stop-postgres-docker.js'
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Starts a PostgreSQL Docker container for testing purposes.
3
+ *
4
+ * If a container with the same name already exists, it will be stopped and removed first.
5
+ * The function blocks until PostgreSQL is ready to accept connections.
6
+ *
7
+ * @param {object} options
8
+ * @param {number} [options.port=5433]
9
+ * Host port to bind PostgreSQL to.
10
+ *
11
+ * @param {string} [options.containerName='postgres-test']
12
+ * Docker container name.
13
+ *
14
+ * @param {string} [options.user='testuser']
15
+ * Database user name.
16
+ *
17
+ * @param {string} [options.pass='testpass']
18
+ * Database user password.
19
+ *
20
+ * @param {string} [options.db='testdb']
21
+ * Database name.
22
+ *
23
+ * @returns {void}
24
+ *
25
+ * @throws {Error}
26
+ * Throws if PostgreSQL does not become ready within the expected time.
27
+ */
28
+ export function startPostgres({
29
+ port,
30
+ containerName,
31
+ user,
32
+ pass,
33
+ db,
34
+ }: {
35
+ port?: number
36
+ containerName?: string
37
+ user?: string
38
+ pass?: string
39
+ db?: string
40
+ }): void
41
+ /**
42
+ * Stops and removes a PostgreSQL Docker container used for testing.
43
+ *
44
+ * If the container does not exist, the function exits silently.
45
+ *
46
+ * @param {string} [containerName='postgres-test']
47
+ * Docker container name.
48
+ *
49
+ * @returns {void}
50
+ */
51
+ export function stopPostgres(containerName?: string): void
52
+ /**
53
+ * Checks whether PostgreSQL inside the Docker container
54
+ * is ready to accept connections.
55
+ *
56
+ * @param {string} containerName
57
+ * Docker container name.
58
+ *
59
+ * @param {string} user
60
+ * Database user name.
61
+ *
62
+ * @param {string} db
63
+ * Database name.
64
+ *
65
+ * @returns {boolean}
66
+ * Returns true if PostgreSQL is ready, otherwise false.
67
+ */
68
+ export function isPostgresReady(
69
+ containerName: string,
70
+ user: string,
71
+ db: string,
72
+ ): boolean
73
+ /**
74
+ * Waits until PostgreSQL inside the Docker container
75
+ * is ready to accept connections.
76
+ *
77
+ * Retries for a fixed number of attempts before failing.
78
+ *
79
+ * @param {string} containerName
80
+ * Docker container name.
81
+ *
82
+ * @param {string} user
83
+ * Database user name.
84
+ *
85
+ * @param {string} db
86
+ * Database name.
87
+ *
88
+ * @returns {void}
89
+ *
90
+ * @throws {Error}
91
+ * Throws if PostgreSQL does not become ready within the timeout.
92
+ */
93
+ export function waitForPostgres(
94
+ containerName: string,
95
+ user: string,
96
+ db: string,
97
+ ): void
98
+ /**
99
+ * Build a PostgreSQL connection URI
100
+ * @param {object} opts
101
+ * @param {string} opts.user
102
+ * @param {string} opts.pass
103
+ * @param {number} opts.port
104
+ * @param {string} opts.db
105
+ */
106
+ export function buildPostgresUri({
107
+ user,
108
+ pass,
109
+ port,
110
+ db,
111
+ }: {
112
+ user: string
113
+ pass: string
114
+ port: number
115
+ db: string
116
+ }): string
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Validates that the specified database tables exist.
3
+ *
4
+ * Checks all provided table names and collects any missing tables.
5
+ * Throws a single error listing all missing tables after validation completes.
6
+ *
7
+ * @param {string|object} connection
8
+ * Database connection configuration.
9
+ * Can be a database connection URI or a Knex connection object.
10
+ *
11
+ * @param {string[]} tables
12
+ * List of required table names to validate.
13
+ *
14
+ * @returns {Promise<void>}
15
+ *
16
+ * @throws {Error}
17
+ * Throws an error if one or more required tables are missing.
18
+ */
19
+ export function validateSchema(
20
+ connection: string | object,
21
+ tables: string[],
22
+ ): Promise<void>