core-services-sdk 1.3.31 → 1.3.33

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.31",
3
+ "version": "1.3.33",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "types": "types/index.d.ts",
@@ -88,3 +88,130 @@ export const generateOnboardingId = () =>
88
88
  * @returns {string} A session ID.
89
89
  */
90
90
  export const generateSessionId = () => generatePrefixedId(ID_PREFIXES.SESSION)
91
+
92
+ /**
93
+ * Generates a file ID with a `fil_` prefix.
94
+ *
95
+ * @returns {string} A file ID.
96
+ */
97
+ export const generateFileId = () => generatePrefixedId(ID_PREFIXES.FILE)
98
+
99
+ /**
100
+ * Generates an event ID with an `evt_` prefix.
101
+ *
102
+ * @returns {string} An event ID.
103
+ */
104
+ export const generateEventId = () => generatePrefixedId(ID_PREFIXES.EVENT)
105
+
106
+ /**
107
+ * Generates a job ID with a `job_` prefix.
108
+ *
109
+ * @returns {string} A job ID.
110
+ */
111
+ export const generateJobId = () => generatePrefixedId(ID_PREFIXES.JOB)
112
+
113
+ /**
114
+ * Generates a task ID with a `task_` prefix.
115
+ *
116
+ * @returns {string} A task ID.
117
+ */
118
+ export const generateTaskId = () => generatePrefixedId(ID_PREFIXES.TASK)
119
+
120
+ /**
121
+ * Generates a queue ID with a `que_` prefix.
122
+ *
123
+ * @returns {string} A queue ID.
124
+ */
125
+ export const generateQueueId = () => generatePrefixedId(ID_PREFIXES.QUEUE)
126
+
127
+ /**
128
+ * Generates a message ID with a `msg_` prefix.
129
+ *
130
+ * @returns {string} A message ID.
131
+ */
132
+ export const generateMessageId = () => generatePrefixedId(ID_PREFIXES.MESSAGE)
133
+
134
+ /**
135
+ * Generates a notification ID with a `ntf_` prefix.
136
+ *
137
+ * @returns {string} A notification ID.
138
+ */
139
+ export const generateNotificationId = () =>
140
+ generatePrefixedId(ID_PREFIXES.NOTIFICATION)
141
+
142
+ /**
143
+ * Generates a log ID with a `log_` prefix.
144
+ *
145
+ * @returns {string} A log ID.
146
+ */
147
+ export const generateLogId = () => generatePrefixedId(ID_PREFIXES.LOG)
148
+
149
+ /**
150
+ * Generates an audit ID with an `adt_` prefix.
151
+ *
152
+ * @returns {string} An audit ID.
153
+ */
154
+ export const generateAuditId = () => generatePrefixedId(ID_PREFIXES.AUDIT)
155
+
156
+ /**
157
+ * Generates a config ID with a `cfg_` prefix.
158
+ *
159
+ * @returns {string} A config ID.
160
+ */
161
+ export const generateConfigId = () => generatePrefixedId(ID_PREFIXES.CONFIG)
162
+
163
+ /**
164
+ * Generates a key ID with a `key_` prefix.
165
+ *
166
+ * @returns {string} A key ID.
167
+ */
168
+ export const generateKeyId = () => generatePrefixedId(ID_PREFIXES.KEY)
169
+
170
+ /**
171
+ * Generates a metric ID with a `met_` prefix.
172
+ *
173
+ * @returns {string} A metric ID.
174
+ */
175
+ export const generateMetricId = () => generatePrefixedId(ID_PREFIXES.METRIC)
176
+
177
+ /**
178
+ * Generates a tag ID with a `tag_` prefix.
179
+ *
180
+ * @returns {string} A tag ID.
181
+ */
182
+ export const generateTagId = () => generatePrefixedId(ID_PREFIXES.TAG)
183
+
184
+ /**
185
+ * Generates a policy ID with a `plc_` prefix.
186
+ *
187
+ * @returns {string} A policy ID.
188
+ */
189
+ export const generatePolicyId = () => generatePrefixedId(ID_PREFIXES.POLICY)
190
+
191
+ /**
192
+ * Generates a profile ID with a `prf_` prefix.
193
+ *
194
+ * @returns {string} A profile ID.
195
+ */
196
+ export const generateProfileId = () => generatePrefixedId(ID_PREFIXES.PROFILE)
197
+
198
+ /**
199
+ * Generates a device ID with a `dev_` prefix.
200
+ *
201
+ * @returns {string} A device ID.
202
+ */
203
+ export const generateDeviceId = () => generatePrefixedId(ID_PREFIXES.DEVICE)
204
+
205
+ /**
206
+ * Generates an alert ID with an `alr_` prefix.
207
+ *
208
+ * @returns {string} An alert ID.
209
+ */
210
+ export const generateAlertId = () => generatePrefixedId(ID_PREFIXES.ALERT)
211
+
212
+ /**
213
+ * Generates a resource ID with a `res_` prefix.
214
+ *
215
+ * @returns {string} A resource ID.
216
+ */
217
+ export const generateResourceId = () => generatePrefixedId(ID_PREFIXES.RESOURCE)
@@ -31,4 +31,58 @@ export const ID_PREFIXES = Object.freeze({
31
31
 
32
32
  /** Session mapping ID prefix */
33
33
  SESSION: 'sess',
34
+
35
+ /** File mapping ID prefix */
36
+ FILE: 'fil',
37
+
38
+ /** Event entity ID prefix */
39
+ EVENT: 'evt',
40
+
41
+ /** Job entity ID prefix */
42
+ JOB: 'job',
43
+
44
+ /** Task entity ID prefix */
45
+ TASK: 'task',
46
+
47
+ /** Queue entity ID prefix */
48
+ QUEUE: 'que',
49
+
50
+ /** Message entity ID prefix */
51
+ MESSAGE: 'msg',
52
+
53
+ /** Notification entity ID prefix */
54
+ NOTIFICATION: 'ntf',
55
+
56
+ /** Log entity ID prefix */
57
+ LOG: 'log',
58
+
59
+ /** Audit entity ID prefix */
60
+ AUDIT: 'adt',
61
+
62
+ /** Config entity ID prefix */
63
+ CONFIG: 'cfg',
64
+
65
+ /** Key entity ID prefix */
66
+ KEY: 'key',
67
+
68
+ /** Metric entity ID prefix */
69
+ METRIC: 'met',
70
+
71
+ /** Tag entity ID prefix */
72
+ TAG: 'tag',
73
+
74
+ /** Policy entity ID prefix */
75
+ POLICY: 'plc',
76
+
77
+ /** Profile entity ID prefix */
78
+ PROFILE: 'prf',
79
+
80
+ /** Device entity ID prefix */
81
+ DEVICE: 'dev',
82
+
83
+ /** Alert entity ID prefix */
84
+ ALERT: 'alr',
85
+
86
+ /** Resource entity ID prefix */
87
+ RESOURCE: 'res',
34
88
  })
@@ -11,6 +11,24 @@ import {
11
11
  generateVerificationId,
12
12
  generateRolePermissionsId,
13
13
  generateSessionId,
14
+ generateFileId,
15
+ generateEventId,
16
+ generateJobId,
17
+ generateTaskId,
18
+ generateQueueId,
19
+ generateMessageId,
20
+ generateNotificationId,
21
+ generateLogId,
22
+ generateAuditId,
23
+ generateConfigId,
24
+ generateKeyId,
25
+ generateMetricId,
26
+ generateTagId,
27
+ generatePolicyId,
28
+ generateProfileId,
29
+ generateDeviceId,
30
+ generateAlertId,
31
+ generateResourceId,
14
32
  } from '../../src/ids/generators.js'
15
33
  import { ID_PREFIXES } from '../../src/ids/prefixes.js'
16
34
 
@@ -79,4 +97,76 @@ describe('generate*Id functions', () => {
79
97
  it('generateSessionId returns ID with sess_ prefix', () => {
80
98
  testPrefixFunction(generateSessionId, ID_PREFIXES.SESSION)
81
99
  })
100
+
101
+ it('generateFileId returns ID with fil_ prefix', () => {
102
+ testPrefixFunction(generateFileId, ID_PREFIXES.FILE)
103
+ })
104
+
105
+ it('generateEventId returns ID with evt_ prefix', () => {
106
+ testPrefixFunction(generateEventId, ID_PREFIXES.EVENT)
107
+ })
108
+
109
+ it('generateJobId returns ID with job_ prefix', () => {
110
+ testPrefixFunction(generateJobId, ID_PREFIXES.JOB)
111
+ })
112
+
113
+ it('generateTaskId returns ID with task_ prefix', () => {
114
+ testPrefixFunction(generateTaskId, ID_PREFIXES.TASK)
115
+ })
116
+
117
+ it('generateQueueId returns ID with que_ prefix', () => {
118
+ testPrefixFunction(generateQueueId, ID_PREFIXES.QUEUE)
119
+ })
120
+
121
+ it('generateMessageId returns ID with msg_ prefix', () => {
122
+ testPrefixFunction(generateMessageId, ID_PREFIXES.MESSAGE)
123
+ })
124
+
125
+ it('generateNotificationId returns ID with ntf_ prefix', () => {
126
+ testPrefixFunction(generateNotificationId, ID_PREFIXES.NOTIFICATION)
127
+ })
128
+
129
+ it('generateLogId returns ID with log_ prefix', () => {
130
+ testPrefixFunction(generateLogId, ID_PREFIXES.LOG)
131
+ })
132
+
133
+ it('generateAuditId returns ID with adt_ prefix', () => {
134
+ testPrefixFunction(generateAuditId, ID_PREFIXES.AUDIT)
135
+ })
136
+
137
+ it('generateConfigId returns ID with cfg_ prefix', () => {
138
+ testPrefixFunction(generateConfigId, ID_PREFIXES.CONFIG)
139
+ })
140
+
141
+ it('generateKeyId returns ID with key_ prefix', () => {
142
+ testPrefixFunction(generateKeyId, ID_PREFIXES.KEY)
143
+ })
144
+
145
+ it('generateMetricId returns ID with met_ prefix', () => {
146
+ testPrefixFunction(generateMetricId, ID_PREFIXES.METRIC)
147
+ })
148
+
149
+ it('generateTagId returns ID with tag_ prefix', () => {
150
+ testPrefixFunction(generateTagId, ID_PREFIXES.TAG)
151
+ })
152
+
153
+ it('generatePolicyId returns ID with plc_ prefix', () => {
154
+ testPrefixFunction(generatePolicyId, ID_PREFIXES.POLICY)
155
+ })
156
+
157
+ it('generateProfileId returns ID with prf_ prefix', () => {
158
+ testPrefixFunction(generateProfileId, ID_PREFIXES.PROFILE)
159
+ })
160
+
161
+ it('generateDeviceId returns ID with dev_ prefix', () => {
162
+ testPrefixFunction(generateDeviceId, ID_PREFIXES.DEVICE)
163
+ })
164
+
165
+ it('generateAlertId returns ID with alr_ prefix', () => {
166
+ testPrefixFunction(generateAlertId, ID_PREFIXES.ALERT)
167
+ })
168
+
169
+ it('generateResourceId returns ID with res_ prefix', () => {
170
+ testPrefixFunction(generateResourceId, ID_PREFIXES.RESOURCE)
171
+ })
82
172
  })
@@ -14,6 +14,24 @@ describe('ID_PREFIXES', () => {
14
14
  ROLE_PERMISSIONS: 'role',
15
15
  ONBOARDING: 'onb',
16
16
  SESSION: 'sess',
17
+ FILE: 'fil',
18
+ EVENT: 'evt',
19
+ JOB: 'job',
20
+ TASK: 'task',
21
+ QUEUE: 'que',
22
+ MESSAGE: 'msg',
23
+ NOTIFICATION: 'ntf',
24
+ LOG: 'log',
25
+ AUDIT: 'adt',
26
+ CONFIG: 'cfg',
27
+ KEY: 'key',
28
+ METRIC: 'met',
29
+ TAG: 'tag',
30
+ POLICY: 'plc',
31
+ PROFILE: 'prf',
32
+ DEVICE: 'dev',
33
+ ALERT: 'alr',
34
+ RESOURCE: 'res',
17
35
  })
18
36
  })
19
37
 
@@ -8,3 +8,21 @@ export function generateVerificationId(): string;
8
8
  export function generateRolePermissionsId(): string;
9
9
  export function generateOnboardingId(): string;
10
10
  export function generateSessionId(): string;
11
+ export function generateFileId(): string;
12
+ export function generateEventId(): string;
13
+ export function generateJobId(): string;
14
+ export function generateTaskId(): string;
15
+ export function generateQueueId(): string;
16
+ export function generateMessageId(): string;
17
+ export function generateNotificationId(): string;
18
+ export function generateLogId(): string;
19
+ export function generateAuditId(): string;
20
+ export function generateConfigId(): string;
21
+ export function generateKeyId(): string;
22
+ export function generateMetricId(): string;
23
+ export function generateTagId(): string;
24
+ export function generatePolicyId(): string;
25
+ export function generateProfileId(): string;
26
+ export function generateDeviceId(): string;
27
+ export function generateAlertId(): string;
28
+ export function generateResourceId(): string;
@@ -31,4 +31,40 @@ export const ID_PREFIXES: Readonly<{
31
31
  ONBOARDING: "onb";
32
32
  /** Session mapping ID prefix */
33
33
  SESSION: "sess";
34
+ /** File mapping ID prefix */
35
+ FILE: "fil";
36
+ /** Event entity ID prefix */
37
+ EVENT: "evt";
38
+ /** Job entity ID prefix */
39
+ JOB: "job";
40
+ /** Task entity ID prefix */
41
+ TASK: "task";
42
+ /** Queue entity ID prefix */
43
+ QUEUE: "que";
44
+ /** Message entity ID prefix */
45
+ MESSAGE: "msg";
46
+ /** Notification entity ID prefix */
47
+ NOTIFICATION: "ntf";
48
+ /** Log entity ID prefix */
49
+ LOG: "log";
50
+ /** Audit entity ID prefix */
51
+ AUDIT: "adt";
52
+ /** Config entity ID prefix */
53
+ CONFIG: "cfg";
54
+ /** Key entity ID prefix */
55
+ KEY: "key";
56
+ /** Metric entity ID prefix */
57
+ METRIC: "met";
58
+ /** Tag entity ID prefix */
59
+ 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 */
69
+ RESOURCE: "res";
34
70
  }>;
@@ -1,4 +1,7 @@
1
- export function mongoConnect({ uri, serverApi }: {
1
+ export function mongoConnect({ uri, serverApi, timeout, retries, }: {
2
2
  uri: string;
3
3
  serverApi?: object;
4
- }): Promise<import("mongodb").MongoClient>;
4
+ timeout?: number;
5
+ retries?: number;
6
+ }): Promise<MongoClient>;
7
+ import { MongoClient } from 'mongodb';
@@ -1,4 +1,5 @@
1
1
  export * from "./connect.js";
2
+ export * from "./paginate.js";
2
3
  export * from "./dsl-to-mongo.js";
3
4
  export * from "./initialize-mongodb.js";
4
5
  export * from "./validate-mongo-uri.js";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Pagination with SQL-like ascending/descending
3
+ *
4
+ * @param {import('mongodb').Collection} collection
5
+ * @param {Object} options
6
+ * @param {Object} [options.filter={}]
7
+ * @param {string} [options.cursorField='_id']
8
+ * @param {string|Date|ObjectId} [options.cursor]
9
+ * @param {'asc'|'desc'} [options.order='asc']
10
+ * @param {number} [options.limit=10]
11
+ */
12
+ export function paginate(collection: import("mongodb").Collection, { limit, projection, filter, cursor, order, cursorField, }?: {
13
+ filter?: any;
14
+ cursorField?: string;
15
+ cursor?: string | Date | ObjectId;
16
+ order?: "asc" | "desc";
17
+ limit?: number;
18
+ }): Promise<{
19
+ order: "desc" | "asc";
20
+ list: import("mongodb").WithId<import("bson").Document>[];
21
+ previous: any;
22
+ next: any;
23
+ }>;
24
+ import { ObjectId } from 'mongodb';
@@ -0,0 +1,55 @@
1
+ export namespace Context {
2
+ /**
3
+ * Run a callback within a given context store.
4
+ * Everything `await`ed or invoked inside this callback will have access
5
+ * to the provided store via {@link Context.get}, {@link Context.set}, or {@link Context.all}.
6
+ *
7
+ * @template T
8
+ * @param {Record<string, any>} store
9
+ * @param {() => T} callback - Function to execute inside the context.
10
+ * @returns {T} The return value of the callback (sync or async).
11
+ *
12
+ * @example
13
+ * Context.run(
14
+ * { correlationId: 'abc123' },
15
+ * async () => {
16
+ * console.log(Context.get('correlationId')) // "abc123"
17
+ * }
18
+ * )
19
+ */
20
+ function run<T>(store: Record<string, any>, callback: () => T): T;
21
+ /**
22
+ * Retrieve a single value from the current async context store.
23
+ *
24
+ * @template T
25
+ * @param {string} key - The key of the value to retrieve.
26
+ * @returns {T|undefined} The stored value, or `undefined` if no store exists or key not found.
27
+ *
28
+ * @example
29
+ * const userId = Context.get('userId')
30
+ */
31
+ function get<T>(key: string): T | undefined;
32
+ /**
33
+ * Set a single key-value pair in the current async context store.
34
+ * If there is no active store (i.e. outside of a {@link Context.run}),
35
+ * this function does nothing.
36
+ *
37
+ * @param {string} key - The key under which to store the value.
38
+ * @param {any} value - The value to store.
39
+ *
40
+ * @example
41
+ * Context.set('tenantId', 'tnt_1234')
42
+ */
43
+ function set(key: string, value: any): void;
44
+ /**
45
+ * Get the entire store object for the current async context.
46
+ *
47
+ * @returns {Record<string, any>} The current store object,
48
+ * or an empty object if no store exists.
49
+ *
50
+ * @example
51
+ * const all = Context.all()
52
+ * console.log(all) // { correlationId: 'abc123', userId: 'usr_789' }
53
+ */
54
+ function all(): Record<string, any>;
55
+ }
@@ -2,6 +2,7 @@ export namespace util {
2
2
  export { mask };
3
3
  export { maskSingle };
4
4
  }
5
+ export { Context } from "./context.js";
5
6
  import { mask } from './mask-sensitive.js';
6
7
  import { maskSingle } from './mask-sensitive.js';
7
8
  export { mask, maskSingle };