core-services-sdk 1.3.41 → 1.3.43

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.41",
3
+ "version": "1.3.43",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "types": "types/index.d.ts",
@@ -215,3 +215,11 @@ export const generateAlertId = () => generatePrefixedId(ID_PREFIXES.ALERT)
215
215
  * @returns {string} A resource ID.
216
216
  */
217
217
  export const generateResourceId = () => generatePrefixedId(ID_PREFIXES.RESOURCE)
218
+
219
+ /**
220
+ * Generates a resource ID with a `ieml_` prefix.
221
+ *
222
+ * @returns {string} An incoming email ID.
223
+ */
224
+ export const generateIncomingEmailId = () =>
225
+ generatePrefixedId(ID_PREFIXES.INCOMING_EMAIL)
@@ -85,4 +85,7 @@ export const ID_PREFIXES = Object.freeze({
85
85
 
86
86
  /** Resource entity ID prefix */
87
87
  RESOURCE: 'res',
88
+
89
+ /** Incoming email ID prefix */
90
+ INCOMING_EMAIL: 'ieml',
88
91
  })
@@ -97,8 +97,6 @@ export async function getPaginationEdges({
97
97
  }
98
98
  }
99
99
 
100
- import { ObjectId } from 'mongodb'
101
-
102
100
  /**
103
101
  * Classic page/limit pagination with total count
104
102
  *
@@ -114,19 +112,23 @@ import { ObjectId } from 'mongodb'
114
112
  export async function paginate(
115
113
  collection,
116
114
  {
115
+ sortBy = '_id',
116
+ page = 1,
117
+ limit = 10,
117
118
  filter = {},
118
119
  projection,
119
120
  order = 'desc',
120
- cursorField = '_id',
121
- limit = 10,
122
- page = 1,
123
121
  } = {},
124
122
  ) {
125
123
  // Validation
126
- if (page < 1) page = 1
127
- if (limit < 1) limit = 10
124
+ if (page < 1) {
125
+ page = 1
126
+ }
127
+ if (limit < 1) {
128
+ limit = 10
129
+ }
128
130
 
129
- const sort = { [cursorField]: order === 'asc' ? 1 : -1 }
131
+ const sort = { [sortBy]: order === 'asc' ? 1 : -1 }
130
132
  const skip = (page - 1) * limit
131
133
 
132
134
  const [results, totalCount] = await Promise.all([
@@ -145,11 +147,11 @@ export async function paginate(
145
147
 
146
148
  return {
147
149
  order,
150
+ hasNext,
148
151
  totalCount,
149
152
  totalPages,
150
- currentPage: page,
151
- hasNext,
152
153
  hasPrevious,
153
154
  list: results,
155
+ currentPage: page,
154
156
  }
155
157
  }
@@ -1,6 +1,5 @@
1
1
  // @ts-nocheck
2
2
  import { describe, it, expect } from 'vitest'
3
-
4
3
  import { ID_PREFIXES } from '../../src/ids/prefixes.js'
5
4
 
6
5
  describe('ID_PREFIXES', () => {
@@ -32,6 +31,7 @@ describe('ID_PREFIXES', () => {
32
31
  DEVICE: 'dev',
33
32
  ALERT: 'alr',
34
33
  RESOURCE: 'res',
34
+ INCOMING_EMAIL: 'ieml', // ✅ added
35
35
  })
36
36
  })
37
37
 
@@ -26,3 +26,4 @@ export function generateProfileId(): string
26
26
  export function generateDeviceId(): string
27
27
  export function generateAlertId(): string
28
28
  export function generateResourceId(): string
29
+ export function generateIncomingEmailId(): string
@@ -67,4 +67,6 @@ export const ID_PREFIXES: Readonly<{
67
67
  ALERT: 'alr'
68
68
  /** Resource entity ID prefix */
69
69
  RESOURCE: 'res'
70
+ /** Incoming email ID prefix */
71
+ INCOMING_EMAIL: 'ieml'
70
72
  }>
@@ -9,7 +9,7 @@
9
9
  * @param {'asc'|'desc'} [options.order='asc']
10
10
  * @param {number} [options.limit=10]
11
11
  */
12
- export function paginate(
12
+ export function paginateCursor(
13
13
  collection: import('mongodb').Collection,
14
14
  {
15
15
  limit,
@@ -48,4 +48,42 @@ export function getPaginationEdges({
48
48
  hasNext: boolean
49
49
  hasPrevious: boolean
50
50
  }>
51
+ /**
52
+ * Classic page/limit pagination with total count
53
+ *
54
+ * @param {import('mongodb').Collection} collection
55
+ * @param {Object} options
56
+ * @param {Object} [options.filter={}] - MongoDB filter
57
+ * @param {string} [options.cursorField='_id'] - Field to sort by
58
+ * @param {'asc'|'desc'} [options.order='desc'] - Sort order
59
+ * @param {number} [options.limit=10] - Items per page
60
+ * @param {number} [options.page=1] - Page number (1-based)
61
+ * @param {Object} [options.projection] - Projection fields
62
+ */
63
+ export function paginate(
64
+ collection: import('mongodb').Collection,
65
+ {
66
+ sortBy,
67
+ page,
68
+ limit,
69
+ filter,
70
+ projection,
71
+ order,
72
+ }?: {
73
+ filter?: any
74
+ cursorField?: string
75
+ order?: 'asc' | 'desc'
76
+ limit?: number
77
+ page?: number
78
+ projection?: any
79
+ },
80
+ ): Promise<{
81
+ order: 'asc' | 'desc'
82
+ hasNext: boolean
83
+ totalCount: number
84
+ totalPages: number
85
+ hasPrevious: boolean
86
+ list: import('mongodb').WithId<import('bson').Document>[]
87
+ currentPage: number
88
+ }>
51
89
  import { ObjectId } from 'mongodb'