@burdenoff/be-sdk 2026.510.79

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.
Files changed (220) hide show
  1. package/README.md +173 -0
  2. package/configs/eslint/index.js +492 -0
  3. package/configs/tsconfig/tsconfig.json +53 -0
  4. package/dist/EventQueueFactory-6NMSGECR.js +8 -0
  5. package/dist/EventQueueFactory-6NMSGECR.js.map +1 -0
  6. package/dist/auth/index.d.ts +66 -0
  7. package/dist/auth/index.js +8 -0
  8. package/dist/auth/index.js.map +1 -0
  9. package/dist/cache/index.d.ts +2 -0
  10. package/dist/cache/index.js +6 -0
  11. package/dist/cache/index.js.map +1 -0
  12. package/dist/captcha/index.d.ts +1 -0
  13. package/dist/captcha/index.js +4 -0
  14. package/dist/captcha/index.js.map +1 -0
  15. package/dist/chunk-2HANKZZM.js +245 -0
  16. package/dist/chunk-2HANKZZM.js.map +1 -0
  17. package/dist/chunk-2SD5L2F2.js +816 -0
  18. package/dist/chunk-2SD5L2F2.js.map +1 -0
  19. package/dist/chunk-3O2RQOPV.js +1068 -0
  20. package/dist/chunk-3O2RQOPV.js.map +1 -0
  21. package/dist/chunk-4B43DZIS.js +560 -0
  22. package/dist/chunk-4B43DZIS.js.map +1 -0
  23. package/dist/chunk-4XAEES25.js +2444 -0
  24. package/dist/chunk-4XAEES25.js.map +1 -0
  25. package/dist/chunk-4XGGWW36.js +1405 -0
  26. package/dist/chunk-4XGGWW36.js.map +1 -0
  27. package/dist/chunk-5LXDPGDH.js +245 -0
  28. package/dist/chunk-5LXDPGDH.js.map +1 -0
  29. package/dist/chunk-AI7L22ZJ.js +472 -0
  30. package/dist/chunk-AI7L22ZJ.js.map +1 -0
  31. package/dist/chunk-CBZNP6RF.js +286 -0
  32. package/dist/chunk-CBZNP6RF.js.map +1 -0
  33. package/dist/chunk-ELLX3K54.js +613 -0
  34. package/dist/chunk-ELLX3K54.js.map +1 -0
  35. package/dist/chunk-F5XEAGHQ.js +1875 -0
  36. package/dist/chunk-F5XEAGHQ.js.map +1 -0
  37. package/dist/chunk-FNZEQOJY.js +628 -0
  38. package/dist/chunk-FNZEQOJY.js.map +1 -0
  39. package/dist/chunk-GTEMQXCA.js +516 -0
  40. package/dist/chunk-GTEMQXCA.js.map +1 -0
  41. package/dist/chunk-HIWTWIGQ.js +226 -0
  42. package/dist/chunk-HIWTWIGQ.js.map +1 -0
  43. package/dist/chunk-IYE2NTRX.js +764 -0
  44. package/dist/chunk-IYE2NTRX.js.map +1 -0
  45. package/dist/chunk-J26YGR2U.js +1484 -0
  46. package/dist/chunk-J26YGR2U.js.map +1 -0
  47. package/dist/chunk-JG2FTZPI.js +509 -0
  48. package/dist/chunk-JG2FTZPI.js.map +1 -0
  49. package/dist/chunk-JVBTNSPG.js +1551 -0
  50. package/dist/chunk-JVBTNSPG.js.map +1 -0
  51. package/dist/chunk-L7ZMN2FJ.js +12 -0
  52. package/dist/chunk-L7ZMN2FJ.js.map +1 -0
  53. package/dist/chunk-M5IMU3US.js +473 -0
  54. package/dist/chunk-M5IMU3US.js.map +1 -0
  55. package/dist/chunk-MLW2HPS5.js +1267 -0
  56. package/dist/chunk-MLW2HPS5.js.map +1 -0
  57. package/dist/chunk-MNCGUYLJ.js +269 -0
  58. package/dist/chunk-MNCGUYLJ.js.map +1 -0
  59. package/dist/chunk-MOCUBSTW.js +373 -0
  60. package/dist/chunk-MOCUBSTW.js.map +1 -0
  61. package/dist/chunk-NGMEI42S.js +103 -0
  62. package/dist/chunk-NGMEI42S.js.map +1 -0
  63. package/dist/chunk-NUB5GQTU.js +270 -0
  64. package/dist/chunk-NUB5GQTU.js.map +1 -0
  65. package/dist/chunk-OVSYMNCI.js +145 -0
  66. package/dist/chunk-OVSYMNCI.js.map +1 -0
  67. package/dist/chunk-QLVKMWFA.js +94 -0
  68. package/dist/chunk-QLVKMWFA.js.map +1 -0
  69. package/dist/chunk-SAG6ZYWQ.js +89 -0
  70. package/dist/chunk-SAG6ZYWQ.js.map +1 -0
  71. package/dist/chunk-SAK2JCA7.js +198 -0
  72. package/dist/chunk-SAK2JCA7.js.map +1 -0
  73. package/dist/chunk-SBS4S2PJ.js +100 -0
  74. package/dist/chunk-SBS4S2PJ.js.map +1 -0
  75. package/dist/chunk-SNEOLWXT.js +148 -0
  76. package/dist/chunk-SNEOLWXT.js.map +1 -0
  77. package/dist/chunk-TKBD2ONF.js +564 -0
  78. package/dist/chunk-TKBD2ONF.js.map +1 -0
  79. package/dist/chunk-UBXFIIAW.js +127 -0
  80. package/dist/chunk-UBXFIIAW.js.map +1 -0
  81. package/dist/chunk-VI4VSNTI.js +57 -0
  82. package/dist/chunk-VI4VSNTI.js.map +1 -0
  83. package/dist/chunk-VWCN5PMD.js +268 -0
  84. package/dist/chunk-VWCN5PMD.js.map +1 -0
  85. package/dist/chunk-XC2YD6CF.js +913 -0
  86. package/dist/chunk-XC2YD6CF.js.map +1 -0
  87. package/dist/chunk-XE4OXN2W.js +10 -0
  88. package/dist/chunk-XE4OXN2W.js.map +1 -0
  89. package/dist/chunk-YMZEUTD2.js +110 -0
  90. package/dist/chunk-YMZEUTD2.js.map +1 -0
  91. package/dist/chunk-Z4IRLBWO.js +758 -0
  92. package/dist/chunk-Z4IRLBWO.js.map +1 -0
  93. package/dist/client/internal-client.d.ts +7 -0
  94. package/dist/client/internal-client.js +5 -0
  95. package/dist/client/internal-client.js.map +1 -0
  96. package/dist/client-CSjIrYKS.d.ts +77 -0
  97. package/dist/config-UKE2E3BW.js +4 -0
  98. package/dist/config-UKE2E3BW.js.map +1 -0
  99. package/dist/crypto/index.d.ts +1 -0
  100. package/dist/crypto/index.js +4 -0
  101. package/dist/crypto/index.js.map +1 -0
  102. package/dist/database/index.d.ts +117 -0
  103. package/dist/database/index.js +7 -0
  104. package/dist/database/index.js.map +1 -0
  105. package/dist/dataloader/index.d.ts +1 -0
  106. package/dist/dataloader/index.js +4 -0
  107. package/dist/dataloader/index.js.map +1 -0
  108. package/dist/esm-K6H7EIWK.js +1450 -0
  109. package/dist/esm-K6H7EIWK.js.map +1 -0
  110. package/dist/event-queue/index.d.ts +6 -0
  111. package/dist/event-queue/index.js +10 -0
  112. package/dist/event-queue/index.js.map +1 -0
  113. package/dist/export/index.d.ts +2 -0
  114. package/dist/export/index.js +9 -0
  115. package/dist/export/index.js.map +1 -0
  116. package/dist/feature-flags/index.d.ts +1 -0
  117. package/dist/feature-flags/index.js +4 -0
  118. package/dist/feature-flags/index.js.map +1 -0
  119. package/dist/gateway/index.d.ts +4 -0
  120. package/dist/gateway/index.js +8 -0
  121. package/dist/gateway/index.js.map +1 -0
  122. package/dist/gateway/security/index.d.ts +2 -0
  123. package/dist/gateway/security/index.js +5 -0
  124. package/dist/gateway/security/index.js.map +1 -0
  125. package/dist/graph/index.d.ts +9 -0
  126. package/dist/graph/index.js +13 -0
  127. package/dist/graph/index.js.map +1 -0
  128. package/dist/graph-emitter-Bk0FqD53.d.ts +47 -0
  129. package/dist/graphql/index.d.ts +2 -0
  130. package/dist/graphql/index.js +7 -0
  131. package/dist/graphql/index.js.map +1 -0
  132. package/dist/graphql/services/index.d.ts +24 -0
  133. package/dist/graphql/services/index.js +5 -0
  134. package/dist/graphql/services/index.js.map +1 -0
  135. package/dist/graphql-BAVrUgBF.d.ts +22 -0
  136. package/dist/i18n/index.d.ts +2 -0
  137. package/dist/i18n/index.js +5 -0
  138. package/dist/i18n/index.js.map +1 -0
  139. package/dist/i18n-DA6IPnYy.d.ts +101 -0
  140. package/dist/index-4gKQKZ2B.d.ts +71 -0
  141. package/dist/index-B18rrFru.d.ts +42 -0
  142. package/dist/index-B70b5mYS.d.ts +33 -0
  143. package/dist/index-BMq3lFjj.d.ts +247 -0
  144. package/dist/index-BODgvRtL.d.ts +316 -0
  145. package/dist/index-BS2idbnr.d.ts +874 -0
  146. package/dist/index-BV3G48cH.d.ts +124 -0
  147. package/dist/index-CHbVw5M7.d.ts +73 -0
  148. package/dist/index-Cq_xNjcv.d.ts +602 -0
  149. package/dist/index-CrQgidpx.d.ts +77 -0
  150. package/dist/index-CyVEg86m.d.ts +309 -0
  151. package/dist/index-DOcBnmMe.d.ts +166 -0
  152. package/dist/index-DSOpj8DI.d.ts +17 -0
  153. package/dist/index-DW9q22GH.d.ts +75 -0
  154. package/dist/index-DlFDFyWD.d.ts +55 -0
  155. package/dist/index-DoK0bjhH.d.ts +607 -0
  156. package/dist/index-Dtf6FBaD.d.ts +199 -0
  157. package/dist/index-KVWGHMbS.d.ts +415 -0
  158. package/dist/index-PaojfSdd.d.ts +71 -0
  159. package/dist/index-RU_M5c74.d.ts +163 -0
  160. package/dist/index-UhkH2eaB.d.ts +192 -0
  161. package/dist/index-e_18DzAg.d.ts +18 -0
  162. package/dist/index-jOuh_TKn.d.ts +59 -0
  163. package/dist/index.d.ts +584 -0
  164. package/dist/index.js +2626 -0
  165. package/dist/index.js.map +1 -0
  166. package/dist/init/index.d.ts +2 -0
  167. package/dist/init/index.js +12 -0
  168. package/dist/init/index.js.map +1 -0
  169. package/dist/instrumentation/index.d.ts +3 -0
  170. package/dist/instrumentation/index.js +5 -0
  171. package/dist/instrumentation/index.js.map +1 -0
  172. package/dist/layer/index.d.ts +2 -0
  173. package/dist/layer/index.js +6 -0
  174. package/dist/layer/index.js.map +1 -0
  175. package/dist/layer-DDip18KY.d.ts +67 -0
  176. package/dist/logger/index.d.ts +2 -0
  177. package/dist/logger/index.js +4 -0
  178. package/dist/logger/index.js.map +1 -0
  179. package/dist/middleware/index.d.ts +3 -0
  180. package/dist/middleware/index.js +5 -0
  181. package/dist/middleware/index.js.map +1 -0
  182. package/dist/notifications/index.d.ts +4 -0
  183. package/dist/notifications/index.js +7 -0
  184. package/dist/notifications/index.js.map +1 -0
  185. package/dist/observability/index.d.ts +3 -0
  186. package/dist/observability/index.js +5 -0
  187. package/dist/observability/index.js.map +1 -0
  188. package/dist/pino-logger-RYLGXPHZ.js +5 -0
  189. package/dist/pino-logger-RYLGXPHZ.js.map +1 -0
  190. package/dist/prisma/generator/index.d.ts +1 -0
  191. package/dist/prisma/generator/index.js +228 -0
  192. package/dist/prisma/generator/index.js.map +1 -0
  193. package/dist/prisma/index.d.ts +5 -0
  194. package/dist/prisma/index.js +12 -0
  195. package/dist/prisma/index.js.map +1 -0
  196. package/dist/prisma-extension-krXnYnrN.d.ts +30 -0
  197. package/dist/rbac/index.d.ts +116 -0
  198. package/dist/rbac/index.js +7 -0
  199. package/dist/rbac/index.js.map +1 -0
  200. package/dist/sdk-THO3IWEE.js +136 -0
  201. package/dist/sdk-THO3IWEE.js.map +1 -0
  202. package/dist/server/index.d.ts +359 -0
  203. package/dist/server/index.js +884 -0
  204. package/dist/server/index.js.map +1 -0
  205. package/dist/telemetry/index.d.ts +83 -0
  206. package/dist/telemetry/index.js +209 -0
  207. package/dist/telemetry/index.js.map +1 -0
  208. package/dist/temporal/index.d.ts +148 -0
  209. package/dist/temporal/index.js +6 -0
  210. package/dist/temporal/index.js.map +1 -0
  211. package/dist/tracker/index.d.ts +5 -0
  212. package/dist/tracker/index.js +9 -0
  213. package/dist/tracker/index.js.map +1 -0
  214. package/dist/types-Bo2wkjSP.d.ts +35 -0
  215. package/dist/utils/index.d.ts +1 -0
  216. package/dist/utils/index.js +4 -0
  217. package/dist/utils/index.js.map +1 -0
  218. package/dist/workspace-guard-LHBNK4TG.js +5 -0
  219. package/dist/workspace-guard-LHBNK4TG.js.map +1 -0
  220. package/package.json +241 -0
@@ -0,0 +1,628 @@
1
+ import { GatewayClient } from './chunk-4B43DZIS.js';
2
+ import { __export, __name } from './chunk-XE4OXN2W.js';
3
+
4
+ // src/export/index.ts
5
+ var export_exports = {};
6
+ __export(export_exports, {
7
+ BaseModuleExporter: () => BaseModuleExporter,
8
+ PaginationService: () => PaginationService,
9
+ convertToCSV: () => convertToCSV,
10
+ csvToJSON: () => csvToJSON,
11
+ estimateCSVSize: () => estimateCSVSize,
12
+ getCSVHeaders: () => getCSVHeaders,
13
+ parseCSV: () => parseCSV,
14
+ triggerExportJob: () => triggerExportJob
15
+ });
16
+
17
+ // src/export/base-exporter.ts
18
+ var BaseModuleExporter = class {
19
+ static {
20
+ __name(this, "BaseModuleExporter");
21
+ }
22
+ /** Unique key identifying this module (e.g., 'users', 'tags', 'orders') */
23
+ moduleKey;
24
+ /** Human-readable display name for the module */
25
+ displayName;
26
+ /** Description of what this module exports */
27
+ description;
28
+ /** Default fields to exclude from export (e.g., sensitive data) */
29
+ defaultExcludeFields;
30
+ /** List of product IDs this exporter supports */
31
+ supportedProducts;
32
+ /** Model name for database operations */
33
+ modelName;
34
+ /**
35
+ * Filter fields from an entity based on exclude list
36
+ *
37
+ * Use this to remove sensitive or unnecessary fields from exported data.
38
+ *
39
+ * @param entity - Entity to filter
40
+ * @param excludeFields - Fields to exclude (uses defaultExcludeFields if not provided)
41
+ * @returns Filtered entity as a plain object
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const user = { id: '1', name: 'John', password: 'secret', ssn: '123' };
46
+ * const filtered = this.filterFields(user, ['password', 'ssn']);
47
+ * // Result: { id: '1', name: 'John' }
48
+ * ```
49
+ */
50
+ filterFields(entity, excludeFields) {
51
+ const fieldsToExclude = excludeFields || this.defaultExcludeFields || [];
52
+ if (fieldsToExclude.length === 0) {
53
+ return entity;
54
+ }
55
+ const filtered = {};
56
+ const record = entity;
57
+ for (const [key, value] of Object.entries(record)) {
58
+ if (!fieldsToExclude.includes(key)) {
59
+ filtered[key] = value;
60
+ }
61
+ }
62
+ return filtered;
63
+ }
64
+ /**
65
+ * Filter multiple entities
66
+ *
67
+ * @param entities - Array of entities to filter
68
+ * @param excludeFields - Fields to exclude
69
+ * @returns Array of filtered entities
70
+ */
71
+ filterFieldsMany(entities, excludeFields) {
72
+ return entities.map((entity) => this.filterFields(entity, excludeFields));
73
+ }
74
+ /**
75
+ * Paginate helper for database queries
76
+ *
77
+ * Use this to implement paginated data fetching in your export method.
78
+ *
79
+ * @param queryFn - Function that executes the paginated query
80
+ * @param page - Page number (1-indexed)
81
+ * @param pageSize - Number of items per page
82
+ * @returns Paginated result with data and metadata
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const result = await this.paginate(
87
+ * async ({ skip, take }) => {
88
+ * const items = await db.user.findMany({ skip, take });
89
+ * const total = await db.user.count();
90
+ * return { items, total };
91
+ * },
92
+ * 1,
93
+ * 100
94
+ * );
95
+ * ```
96
+ */
97
+ async paginate(queryFn, page = 1, pageSize = 100) {
98
+ const skip = (page - 1) * pageSize;
99
+ const take = pageSize;
100
+ const { items, total } = await queryFn({
101
+ skip,
102
+ take
103
+ });
104
+ return {
105
+ data: items,
106
+ total,
107
+ hasMore: skip + items.length < total,
108
+ nextCursor: items.length > 0 && skip + items.length < total ? String(page + 1) : void 0
109
+ };
110
+ }
111
+ /**
112
+ * Fetch all data using cursor-based pagination
113
+ *
114
+ * Use this for exporting large datasets efficiently.
115
+ *
116
+ * @param fetchBatch - Function to fetch a batch of data
117
+ * @param batchSize - Number of items per batch
118
+ * @returns All fetched items
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const allUsers = await this.fetchAll(
123
+ * async (cursor) => db.user.findMany({
124
+ * where: cursor ? { id: { gt: cursor } } : undefined,
125
+ * orderBy: { id: 'asc' },
126
+ * take: 100,
127
+ * }),
128
+ * 100
129
+ * );
130
+ * ```
131
+ */
132
+ async fetchAll(fetchBatch, batchSize = 100) {
133
+ const allItems = [];
134
+ let cursor;
135
+ while (true) {
136
+ const batch = await fetchBatch(cursor);
137
+ if (batch.length === 0) {
138
+ break;
139
+ }
140
+ allItems.push(...batch);
141
+ const lastItem = batch[batch.length - 1];
142
+ if (lastItem) {
143
+ cursor = lastItem.id;
144
+ }
145
+ if (batch.length < batchSize) {
146
+ break;
147
+ }
148
+ }
149
+ return allItems;
150
+ }
151
+ /**
152
+ * Transform entity for export
153
+ *
154
+ * Override this method to customize how entities are transformed before export.
155
+ * Default implementation returns the entity as-is after field filtering.
156
+ *
157
+ * @param entity - Entity to transform
158
+ * @param excludeFields - Fields to exclude
159
+ * @returns Transformed entity
160
+ */
161
+ transformForExport(entity, excludeFields) {
162
+ return this.filterFields(entity, excludeFields);
163
+ }
164
+ /**
165
+ * Validate export options
166
+ *
167
+ * Override this to add custom validation for export options.
168
+ *
169
+ * @param options - Export options to validate
170
+ * @throws Error if options are invalid
171
+ */
172
+ validateOptions(options) {
173
+ const validFormats = [
174
+ "csv",
175
+ "json",
176
+ "xlsx"
177
+ ];
178
+ if (!validFormats.includes(options.format)) {
179
+ throw new Error(`Invalid export format: ${options.format}. Valid formats: ${validFormats.join(", ")}`);
180
+ }
181
+ }
182
+ /**
183
+ * Get supported export formats
184
+ *
185
+ * @returns Array of supported format strings
186
+ */
187
+ getSupportedFormats() {
188
+ return [
189
+ "csv",
190
+ "json",
191
+ "xlsx"
192
+ ];
193
+ }
194
+ /**
195
+ * Get module metadata
196
+ *
197
+ * @returns Module metadata object
198
+ */
199
+ getMetadata() {
200
+ return {
201
+ moduleKey: this.moduleKey,
202
+ displayName: this.displayName,
203
+ description: this.description,
204
+ supportedProducts: this.supportedProducts,
205
+ supportedFormats: this.getSupportedFormats()
206
+ };
207
+ }
208
+ };
209
+
210
+ // src/export/pagination.ts
211
+ var PaginationService = class _PaginationService {
212
+ static {
213
+ __name(this, "PaginationService");
214
+ }
215
+ /**
216
+ * Paginate an array of items using offset-based pagination
217
+ *
218
+ * @param items - Array of items to paginate
219
+ * @param params - Pagination parameters
220
+ * @returns Paginated result with items and metadata
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const allUsers = await db.user.findMany();
225
+ * const page = PaginationService.paginate(allUsers, { page: 1, pageSize: 10 });
226
+ * console.log(page.items); // First 10 users
227
+ * console.log(page.pageInfo.hasNextPage); // true if more pages exist
228
+ * ```
229
+ */
230
+ static paginate(items, params) {
231
+ const page = params.page ?? 1;
232
+ const pageSize = params.pageSize ?? 20;
233
+ const start = (page - 1) * pageSize;
234
+ const end = start + pageSize;
235
+ const paginatedItems = items.slice(start, end);
236
+ return {
237
+ items: paginatedItems,
238
+ totalCount: items.length,
239
+ pageInfo: {
240
+ hasNextPage: end < items.length,
241
+ hasPreviousPage: page > 1,
242
+ startCursor: paginatedItems.length > 0 ? String(start) : void 0,
243
+ endCursor: paginatedItems.length > 0 ? String(Math.min(end, items.length) - 1) : void 0
244
+ }
245
+ };
246
+ }
247
+ /**
248
+ * Calculate pagination metadata without slicing data
249
+ *
250
+ * @param totalCount - Total number of items
251
+ * @param page - Current page number (1-indexed)
252
+ * @param pageSize - Items per page
253
+ * @returns Pagination metadata
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const meta = PaginationService.calculatePagination(150, 3, 20);
258
+ * // meta.hasNextPage = true (page 4 exists)
259
+ * // meta.hasPreviousPage = true (page 2 exists)
260
+ * // meta.totalPages = 8
261
+ * ```
262
+ */
263
+ static calculatePagination(totalCount, page, pageSize) {
264
+ const totalPages = Math.ceil(totalCount / pageSize);
265
+ const startIndex = (page - 1) * pageSize;
266
+ const endIndex = Math.min(startIndex + pageSize - 1, totalCount - 1);
267
+ return {
268
+ hasNextPage: page < totalPages,
269
+ hasPreviousPage: page > 1,
270
+ totalPages,
271
+ currentPage: page,
272
+ pageSize,
273
+ startIndex,
274
+ endIndex
275
+ };
276
+ }
277
+ /**
278
+ * Async generator for paginated database queries using cursor-based pagination
279
+ *
280
+ * This is ideal for processing large datasets without loading everything into memory.
281
+ * The generator yields items one at a time, fetching new batches as needed.
282
+ *
283
+ * @param fetchFn - Function to fetch data given a cursor
284
+ * @param options - Pagination options
285
+ * @returns Async generator of items
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * // Define fetch function that queries the database
290
+ * const fetchUsers = async (cursor?: string) => {
291
+ * return db.user.findMany({
292
+ * where: cursor ? { id: { gt: cursor } } : undefined,
293
+ * orderBy: { id: 'asc' },
294
+ * take: 100,
295
+ * });
296
+ * };
297
+ *
298
+ * // Process all users without loading all into memory
299
+ * for await (const user of PaginationService.paginatedQuery(fetchUsers)) {
300
+ * await processUser(user);
301
+ * }
302
+ * ```
303
+ */
304
+ static async *paginatedQuery(fetchFn, options = {}) {
305
+ const { limit, initialCursor } = options;
306
+ let cursor = initialCursor;
307
+ let hasMore = true;
308
+ let totalYielded = 0;
309
+ while (hasMore) {
310
+ const items = await fetchFn(cursor);
311
+ if (items.length === 0) {
312
+ break;
313
+ }
314
+ for (const item of items) {
315
+ yield item;
316
+ totalYielded++;
317
+ if (limit && totalYielded >= limit) {
318
+ return;
319
+ }
320
+ }
321
+ const lastItem = items[items.length - 1];
322
+ if (lastItem) {
323
+ cursor = lastItem.id;
324
+ }
325
+ hasMore = items.length > 0;
326
+ }
327
+ }
328
+ /**
329
+ * Collect all items from a paginated query into an array
330
+ *
331
+ * @param fetchFn - Function to fetch data given a cursor
332
+ * @param options - Pagination options
333
+ * @returns Array of all items
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * const allUsers = await PaginationService.collectPaginatedQuery(fetchUsers, { limit: 1000 });
338
+ * ```
339
+ */
340
+ static async collectPaginatedQuery(fetchFn, options = {}) {
341
+ const items = [];
342
+ for await (const item of _PaginationService.paginatedQuery(fetchFn, options)) {
343
+ items.push(item);
344
+ }
345
+ return items;
346
+ }
347
+ /**
348
+ * Create a cursor-based paginated fetch function from a Prisma-style query
349
+ *
350
+ * @param queryFn - Prisma-style query function
351
+ * @param batchSize - Number of items to fetch per batch
352
+ * @returns Fetch function compatible with paginatedQuery
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const fetchFn = PaginationService.createPrismaFetchFn(
357
+ * (cursor) => db.user.findMany({
358
+ * where: { isActive: true, ...(cursor ? { id: { gt: cursor } } : {}) },
359
+ * orderBy: { id: 'asc' },
360
+ * take: 100,
361
+ * }),
362
+ * 100
363
+ * );
364
+ *
365
+ * for await (const user of PaginationService.paginatedQuery(fetchFn)) {
366
+ * console.log(user);
367
+ * }
368
+ * ```
369
+ */
370
+ static createPrismaFetchFn(queryFn, _batchSize = 100) {
371
+ return queryFn;
372
+ }
373
+ /**
374
+ * Calculate offset for skip-based pagination
375
+ *
376
+ * @param page - Page number (1-indexed)
377
+ * @param pageSize - Items per page
378
+ * @returns Offset value for skip
379
+ */
380
+ static calculateOffset(page, pageSize) {
381
+ return (Math.max(1, page) - 1) * pageSize;
382
+ }
383
+ /**
384
+ * Parse cursor string to extract pagination state
385
+ *
386
+ * @param cursor - Base64-encoded cursor string
387
+ * @returns Decoded cursor data or null if invalid
388
+ */
389
+ static parseCursor(cursor) {
390
+ try {
391
+ const decoded = Buffer.from(cursor, "base64").toString("utf-8");
392
+ return JSON.parse(decoded);
393
+ } catch {
394
+ return null;
395
+ }
396
+ }
397
+ /**
398
+ * Create cursor string from pagination state
399
+ *
400
+ * @param data - Data to encode in cursor
401
+ * @returns Base64-encoded cursor string
402
+ */
403
+ static createCursor(data) {
404
+ return Buffer.from(JSON.stringify(data)).toString("base64");
405
+ }
406
+ };
407
+
408
+ // src/export/csv.ts
409
+ var FORMULA_PREFIX_RE = /^[=+\-@]/;
410
+ function sanitizeCSVCell(value) {
411
+ return FORMULA_PREFIX_RE.test(value) ? `'${value}` : value;
412
+ }
413
+ __name(sanitizeCSVCell, "sanitizeCSVCell");
414
+ function convertToCSV(data, options = {}) {
415
+ const { delimiter = ",", includeHeaders = true, flattenFields = true, maxFlattenDepth = 3 } = options;
416
+ if (data.length === 0) {
417
+ return "";
418
+ }
419
+ const flattenObject = /* @__PURE__ */ __name((obj, prefix = "", depth = 0) => {
420
+ const result = {};
421
+ if (obj === null || obj === void 0) {
422
+ return result;
423
+ }
424
+ if (typeof obj !== "object") {
425
+ return {
426
+ [prefix || "value"]: String(obj)
427
+ };
428
+ }
429
+ for (const [key, value] of Object.entries(obj)) {
430
+ const newKey = prefix ? `${prefix}.${key}` : key;
431
+ if (value === null || value === void 0) {
432
+ result[newKey] = "";
433
+ } else if (value instanceof Date) {
434
+ result[newKey] = value.toISOString();
435
+ } else if (Array.isArray(value)) {
436
+ result[newKey] = JSON.stringify(value);
437
+ } else if (typeof value === "object" && flattenFields && depth < maxFlattenDepth) {
438
+ Object.assign(result, flattenObject(value, newKey, depth + 1));
439
+ } else if (typeof value === "object") {
440
+ result[newKey] = JSON.stringify(value);
441
+ } else {
442
+ result[newKey] = String(value);
443
+ }
444
+ }
445
+ return result;
446
+ }, "flattenObject");
447
+ const flattenedRecords = data.map((item) => flattenObject(item));
448
+ const allKeys = /* @__PURE__ */ new Set();
449
+ for (const record of flattenedRecords) {
450
+ for (const key of Object.keys(record)) {
451
+ allKeys.add(key);
452
+ }
453
+ }
454
+ const headers = Array.from(allKeys).sort((a, b) => a.localeCompare(b));
455
+ const escapeCSV = /* @__PURE__ */ __name((value) => {
456
+ const sanitizedValue = sanitizeCSVCell(value);
457
+ if (sanitizedValue.includes(delimiter) || sanitizedValue.includes('"') || sanitizedValue.includes("\n") || sanitizedValue.includes("\r")) {
458
+ return `"${sanitizedValue.replace(/"/g, '""')}"`;
459
+ }
460
+ return sanitizedValue;
461
+ }, "escapeCSV");
462
+ const lines = [];
463
+ if (includeHeaders) {
464
+ lines.push(headers.map(escapeCSV).join(delimiter));
465
+ }
466
+ for (const record of flattenedRecords) {
467
+ const row = headers.map((header) => escapeCSV(record[header] || ""));
468
+ lines.push(row.join(delimiter));
469
+ }
470
+ return lines.join("\n");
471
+ }
472
+ __name(convertToCSV, "convertToCSV");
473
+ function parseCSV(csv, options = {}) {
474
+ const { delimiter = ",", hasHeaders = true } = options;
475
+ const lines = csv.split(/\r?\n/).filter((line) => line.trim());
476
+ if (lines.length === 0) {
477
+ return [];
478
+ }
479
+ const parseLine = /* @__PURE__ */ __name((line) => {
480
+ const values = [];
481
+ let current = "";
482
+ let inQuotes = false;
483
+ let i = 0;
484
+ while (i < line.length) {
485
+ const char = line[i];
486
+ const nextChar = line[i + 1];
487
+ if (char === '"' && inQuotes && nextChar === '"') {
488
+ current += '"';
489
+ i += 2;
490
+ } else if (char === '"') {
491
+ inQuotes = !inQuotes;
492
+ i++;
493
+ } else if (char === delimiter && !inQuotes) {
494
+ values.push(current);
495
+ current = "";
496
+ i++;
497
+ } else {
498
+ current += char;
499
+ i++;
500
+ }
501
+ }
502
+ values.push(current);
503
+ return values;
504
+ }, "parseLine");
505
+ let headers;
506
+ let dataLines;
507
+ const firstLine = lines[0];
508
+ if (hasHeaders) {
509
+ headers = parseLine(firstLine);
510
+ dataLines = lines.slice(1);
511
+ } else {
512
+ const firstRow = parseLine(firstLine);
513
+ headers = firstRow.map((_, i) => `col${i}`);
514
+ dataLines = lines;
515
+ }
516
+ return dataLines.map((line) => {
517
+ const values = parseLine(line);
518
+ const obj = {};
519
+ headers.forEach((header, i) => {
520
+ obj[header] = values[i] || "";
521
+ });
522
+ return obj;
523
+ });
524
+ }
525
+ __name(parseCSV, "parseCSV");
526
+ function csvToJSON(csv, options = {}) {
527
+ const { pretty = false, ...parseOptions } = options;
528
+ const data = parseCSV(csv, parseOptions);
529
+ return pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
530
+ }
531
+ __name(csvToJSON, "csvToJSON");
532
+ function getCSVHeaders(data, flattenFields = true) {
533
+ if (data.length === 0) {
534
+ return [];
535
+ }
536
+ const collectKeys = /* @__PURE__ */ __name((obj, prefix = "", depth = 0) => {
537
+ const keys = [];
538
+ if (obj === null || obj === void 0 || typeof obj !== "object") {
539
+ return prefix ? [
540
+ prefix
541
+ ] : [];
542
+ }
543
+ for (const [key, value] of Object.entries(obj)) {
544
+ const fullKey = prefix ? `${prefix}.${key}` : key;
545
+ if (value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && flattenFields && depth < 3) {
546
+ keys.push(...collectKeys(value, fullKey, depth + 1));
547
+ } else {
548
+ keys.push(fullKey);
549
+ }
550
+ }
551
+ return keys;
552
+ }, "collectKeys");
553
+ const allKeys = /* @__PURE__ */ new Set();
554
+ for (const item of data) {
555
+ for (const key of collectKeys(item)) {
556
+ allKeys.add(key);
557
+ }
558
+ }
559
+ return Array.from(allKeys).sort((a, b) => a.localeCompare(b));
560
+ }
561
+ __name(getCSVHeaders, "getCSVHeaders");
562
+ function estimateCSVSize(data, sampleSize = 100) {
563
+ if (data.length === 0) {
564
+ return 0;
565
+ }
566
+ const sample = data.slice(0, Math.min(sampleSize, data.length));
567
+ const sampleCSV = convertToCSV(sample);
568
+ const averageRowSize = sampleCSV.length / sample.length;
569
+ const headers = getCSVHeaders(data);
570
+ const headerSize = headers.join(",").length + 1;
571
+ return Math.ceil(headerSize + averageRowSize * data.length);
572
+ }
573
+ __name(estimateCSVSize, "estimateCSVSize");
574
+
575
+ // src/export/gateway-client.ts
576
+ var CREATE_EXPORT_JOB_MUTATION = `mutation CreateExportJob($input: CreateExportJobInput!) {
577
+ createExportJob(input: $input) {
578
+ id
579
+ status
580
+ workspaceId
581
+ entityTypes
582
+ format
583
+ createdAt
584
+ }
585
+ }`;
586
+ async function triggerExportJob(params) {
587
+ const { serviceName, layer = "wspace", actorId, actorType, workspaceId, name, entityTypes, format, includeMetadata, dateRangeStart, dateRangeEnd } = params;
588
+ const client = new GatewayClient({
589
+ layer,
590
+ serviceName
591
+ });
592
+ const input = {
593
+ workspaceId,
594
+ name,
595
+ entityTypes,
596
+ format,
597
+ ...includeMetadata !== void 0 ? {
598
+ includeMetadata
599
+ } : {},
600
+ ...dateRangeStart !== void 0 ? {
601
+ dateRangeStart
602
+ } : {},
603
+ ...dateRangeEnd !== void 0 ? {
604
+ dateRangeEnd
605
+ } : {}
606
+ };
607
+ const response = await client.internalQuery({
608
+ query: CREATE_EXPORT_JOB_MUTATION,
609
+ variables: {
610
+ input
611
+ },
612
+ headers: {
613
+ "x-actor-id": actorId,
614
+ "x-actor-type": actorType,
615
+ "x-workspace-id": workspaceId
616
+ }
617
+ });
618
+ const job = response.data?.createExportJob;
619
+ if (!job) {
620
+ throw new Error("Export service did not return a job");
621
+ }
622
+ return job;
623
+ }
624
+ __name(triggerExportJob, "triggerExportJob");
625
+
626
+ export { BaseModuleExporter, PaginationService, convertToCSV, csvToJSON, estimateCSVSize, export_exports, getCSVHeaders, parseCSV, triggerExportJob };
627
+ //# sourceMappingURL=chunk-FNZEQOJY.js.map
628
+ //# sourceMappingURL=chunk-FNZEQOJY.js.map