@develit-io/backend-sdk 5.15.2 → 5.16.0

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/dist/index.cjs CHANGED
@@ -3,17 +3,14 @@
3
3
  const drizzleOrm = require('drizzle-orm');
4
4
  const pgCore = require('drizzle-orm/pg-core');
5
5
  const sqliteCore = require('drizzle-orm/sqlite-core');
6
- const commentJson = require('comment-json');
7
- const node_fs = require('node:fs');
8
- const path = require('@std/path');
9
6
  const text = require('@std/text');
10
7
  require('http-status-codes');
11
8
  const z = require('zod/v4/core');
12
9
  const h3 = require('h3');
13
- const consola = require('consola');
14
10
  const fs = require('fs');
15
11
  const crypto$1 = require('node:crypto');
16
- const path$1 = require('path');
12
+ const path = require('path');
13
+ const commentJson = require('comment-json');
17
14
  const superjson = require('superjson');
18
15
 
19
16
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -33,7 +30,7 @@ function _interopNamespaceCompat(e) {
33
30
  const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
34
31
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
35
32
  const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto$1);
36
- const path__default = /*#__PURE__*/_interopDefaultCompat(path$1);
33
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
37
34
  const superjson__default = /*#__PURE__*/_interopDefaultCompat(superjson);
38
35
 
39
36
  const base = {
@@ -54,85 +51,24 @@ const basePostgres = {
54
51
  }).default(drizzleOrm.sql`null`)
55
52
  };
56
53
 
57
- const composeD1Arguments = ({
58
- resourceName
59
- }) => {
60
- return {
61
- transform: {
62
- database: {
63
- name: resourceName,
64
- primaryLocationHint: "weur"
65
- }
66
- }
67
- };
68
- };
69
-
70
- const composeKvArguments = ({
71
- resourceName
72
- }) => {
73
- return {
74
- transform: {
75
- namespace: {
76
- title: resourceName
77
- }
78
- }
79
- };
80
- };
81
-
82
- const composeQueueArguments = ({
83
- resourceName,
84
- deliveryDelay = 5,
85
- messageRetentionPeriod = 259200
86
- }) => {
87
- return {
88
- transform: {
89
- queue: {
90
- queueName: resourceName,
91
- settings: {
92
- deliveryDelay,
93
- messageRetentionPeriod
94
- }
95
- }
96
- }
97
- };
98
- };
99
-
100
- const composeR2Arguments = ({
101
- resourceName,
102
- storageClass = "Standard"
103
- }) => {
104
- return {
105
- transform: {
106
- bucket: {
107
- name: resourceName,
108
- jurisdiction: "eu",
109
- location: "weur",
110
- storageClass
111
- }
112
- }
113
- };
114
- };
115
-
116
- async function loadWorkerConfig({ path: path$1 }) {
117
- const workerConfigFile = node_fs.readFileSync(path.join(path$1, "./wrangler.jsonc"), "utf-8");
118
- return commentJson.parse(workerConfigFile);
119
- }
120
-
121
- const composeBindingName = ({
122
- resource,
123
- resourceName,
124
- bindingName
125
- }) => {
126
- const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
127
- return convertedBindingName.toUpperCase();
128
- };
129
- const composeResourceName = ({
130
- project,
131
- environment,
132
- resourceName
133
- }) => {
134
- return `${project}-${resourceName}-${environment}`;
135
- };
54
+ const bankAccount = sqliteCore.sqliteTable("bank_account", {
55
+ holderName: sqliteCore.text("holder_name").notNull(),
56
+ number: sqliteCore.text("number").notNull(),
57
+ bankCode: sqliteCore.text("bank_code").$type().notNull(),
58
+ iban: sqliteCore.text("iban").notNull(),
59
+ bic: sqliteCore.text("bic").notNull(),
60
+ currency: sqliteCore.text("currency").$type(),
61
+ countryCode: sqliteCore.text("country_code").notNull()
62
+ });
63
+ const bankAccountPostgres = pgCore.pgTable("bank_account", {
64
+ holderName: pgCore.text("holder_name").notNull(),
65
+ number: pgCore.text("number").notNull(),
66
+ bankCode: pgCore.text("bank_code").$type().notNull(),
67
+ iban: pgCore.text("iban").notNull(),
68
+ bic: pgCore.text("bic").notNull(),
69
+ currency: pgCore.text("currency").$type(),
70
+ countryCode: pgCore.text("country_code").notNull()
71
+ });
136
72
 
137
73
  class Infrastructure {
138
74
  project;
@@ -147,19 +83,158 @@ class Infrastructure {
147
83
  this.environment = environment;
148
84
  this.sst = sst;
149
85
  }
86
+ // TODO(Pookensivee): Make tests for this util
87
+ composeBindingName({
88
+ resource,
89
+ resourceName,
90
+ bindingName
91
+ }) {
92
+ const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
93
+ return convertedBindingName.toUpperCase();
94
+ }
95
+ // TODO(Pookensivee): Make tests for this util
96
+ composeResourceName({ resourceName }) {
97
+ return `${this.project}-${resourceName}-${this.environment}`;
98
+ }
99
+ // TODO(Pookensivee): Make tests for this util
100
+ composeKvArguments({ resourceName }) {
101
+ return {
102
+ transform: {
103
+ namespace: {
104
+ title: resourceName
105
+ }
106
+ }
107
+ };
108
+ }
109
+ // TODO(Pookensivee): Make tests for this util
110
+ composeD1Arguments({ resourceName }) {
111
+ return {
112
+ transform: {
113
+ database: {
114
+ name: resourceName,
115
+ primaryLocationHint: "weur"
116
+ }
117
+ }
118
+ };
119
+ }
120
+ // TODO(Pookensivee): Make tests for this util
121
+ composeQueueArguments({
122
+ resourceName,
123
+ deliveryDelay = 5,
124
+ messageRetentionPeriod = 259200
125
+ }) {
126
+ return {
127
+ transform: {
128
+ queue: {
129
+ queueName: resourceName,
130
+ settings: {
131
+ deliveryDelay,
132
+ messageRetentionPeriod
133
+ }
134
+ }
135
+ }
136
+ };
137
+ }
138
+ // TODO(Pookensivee): Make tests for this util
139
+ composeR2Arguments({
140
+ resourceName,
141
+ storageClass = "Standard"
142
+ }) {
143
+ return {
144
+ transform: {
145
+ bucket: {
146
+ name: resourceName,
147
+ jurisdiction: "eu",
148
+ location: "weur",
149
+ storageClass
150
+ }
151
+ }
152
+ };
153
+ }
154
+ // TODO: Solve the circular dependency on post infrastructure deploy script
155
+ // TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
156
+ // async composeWorkerArguments({
157
+ // resourceName,
158
+ // path,
159
+ // bindings = [],
160
+ // }: {
161
+ // resourceName: string
162
+ // path: string
163
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
164
+ // }) {
165
+ // const workerConfig = this.loadWorkerConfig({ path })
166
+ // const environmentVariables = this.extractEnvironmentVariables({ workerConfigEnv:
167
+ // workerConfig.env as WorkerConfigEnv
168
+ // })
169
+ // // TODO: Fix this
170
+ // if (
171
+ // 'SERVICE_CONFIG' in environmentVariables &&
172
+ // typeof environmentVariables.SERVICE_CONFIG === 'object'
173
+ // ) {
174
+ // environmentVariables.SERVICE_CONFIG = JSON.stringify(environmentVariables.SERVICE_CONFIG)
175
+ // }
176
+ // // TODO: Fix this
177
+ // if (
178
+ // 'EMAIL_SENDER' in environmentVariables &&
179
+ // typeof environmentVariables.EMAIL_SENDER === 'object'
180
+ // ) {
181
+ // environmentVariables.EMAIL_SENDER = JSON.stringify(environmentVariables.EMAIL_SENDER)
182
+ // }
183
+ // return {
184
+ // handler: join(path, './src/index.ts'),
185
+ // environment: Object.entries(environmentVariables).reduce((acc, [key, value]) => ({
186
+ // ...acc,
187
+ // [key]: String(value)
188
+ // }), {} as Record<string, string>),
189
+ // link: bindings,
190
+ // transform: {
191
+ // worker: {
192
+ // scriptName: this.composeResourceName({ resourceName }),
193
+ // compatibilityDate: '2025-06-04',
194
+ // compatibilityFlags: ['nodejs_compat'],
195
+ // observability: {
196
+ // enabled: true,
197
+ // headSamplingRate: 1,
198
+ // logs: {
199
+ // // Check whether this disables logs completely or just invocation ones
200
+ // enabled: false,
201
+ // invocationLogs: false,
202
+ // },
203
+ // },
204
+ // },
205
+ // }
206
+ // } satisfies Partial<WorkerArgs>
207
+ // }
208
+ // loadWorkerConfig({ path }: { path: string }) {
209
+ // const workerConfigFile = readFileSync(
210
+ // join(path, './wrangler.jsonc'),
211
+ // 'utf-8',
212
+ // )
213
+ // TODO: Use parse from comment-json
214
+ // const jsonString = workerConfigFile
215
+ // .replace(/\/\*[\s\S]*?\*\//g, '')
216
+ // .replace(/\/\/.*$/gm, '')
217
+ // return JSON.parse(jsonString)
218
+ // }
219
+ // extractEnvironmentVariables({
220
+ // workerConfigEnv,
221
+ // }: {
222
+ // workerConfigEnv: WorkerConfigEnv
223
+ // }) {
224
+ // if (typeof this.environment === 'number') {
225
+ // return { ...workerConfigEnv.dev.vars, ENVIRONMENT: this.environment }
226
+ // }
227
+ // return { ...workerConfigEnv[this.environment].vars }
228
+ // }
150
229
  /**
151
230
  * Creates an instance of Cloudflare KV.
152
231
  */
153
232
  kv(options) {
154
233
  const { resourceName, bindingName } = options;
155
234
  return new this.sst.cloudflare.Kv(
156
- `${composeBindingName({ resource: "kv", resourceName, bindingName })}`,
157
- composeKvArguments({
158
- resourceName: composeResourceName({
159
- project: this.project,
160
- environment: this.environment,
161
- resourceName
162
- })
235
+ `${this.composeBindingName({ resource: "kv", resourceName, bindingName })}`,
236
+ this.composeKvArguments({
237
+ resourceName: this.composeResourceName({ resourceName })
163
238
  })
164
239
  );
165
240
  }
@@ -169,13 +244,9 @@ class Infrastructure {
169
244
  d1(options) {
170
245
  const { resourceName, bindingName } = options;
171
246
  return new this.sst.cloudflare.D1(
172
- `${composeBindingName({ resource: "d1", resourceName, bindingName })}`,
173
- composeD1Arguments({
174
- resourceName: composeResourceName({
175
- project: this.project,
176
- environment: this.environment,
177
- resourceName
178
- })
247
+ `${this.composeBindingName({ resource: "d1", resourceName, bindingName })}`,
248
+ this.composeD1Arguments({
249
+ resourceName: this.composeResourceName({ resourceName })
179
250
  })
180
251
  );
181
252
  }
@@ -185,13 +256,9 @@ class Infrastructure {
185
256
  queue(options) {
186
257
  const { resourceName, bindingName, deliveryDelay, messageRetentionPeriod } = options;
187
258
  return new this.sst.cloudflare.Queue(
188
- `${composeBindingName({ resource: "queue", resourceName, bindingName })}`,
189
- composeQueueArguments({
190
- resourceName: composeResourceName({
191
- project: this.project,
192
- environment: this.environment,
193
- resourceName
194
- }),
259
+ `${this.composeBindingName({ resource: "queue", resourceName, bindingName })}`,
260
+ this.composeQueueArguments({
261
+ resourceName: this.composeResourceName({ resourceName }),
195
262
  deliveryDelay,
196
263
  messageRetentionPeriod
197
264
  })
@@ -203,28 +270,77 @@ class Infrastructure {
203
270
  r2(options) {
204
271
  const { resourceName, bindingName, storageClass } = options;
205
272
  return new this.sst.cloudflare.Bucket(
206
- `${composeBindingName({ resource: "r2", resourceName, bindingName })}`,
207
- composeR2Arguments({
208
- resourceName: composeResourceName({
209
- project: this.project,
210
- environment: this.environment,
211
- resourceName
212
- }),
273
+ `${this.composeBindingName({ resource: "r2", resourceName, bindingName })}`,
274
+ this.composeR2Arguments({
275
+ resourceName: this.composeResourceName({ resourceName }),
213
276
  storageClass
214
277
  })
215
278
  );
216
279
  }
280
+ // TODO: Solve the circular dependency on post infrastructure deploy script
281
+ // async worker({
282
+ // resourceName,
283
+ // bindingName,
284
+ // path,
285
+ // bindings = [],
286
+ // }: {
287
+ // resourceName: string
288
+ // bindingName: string
289
+ // path: string
290
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
291
+ // }) {
292
+ // return new sst.cloudflare.Worker(
293
+ // this.composeBindingName({
294
+ // resource: 'worker',
295
+ // bindingName,
296
+ // resourceName,
297
+ // }),
298
+ // await this.composeWorkerArguments({
299
+ // resourceName: this.composeResourceName({ resourceName }),
300
+ // path,
301
+ // bindings,
302
+ // }),
303
+ // )
304
+ // }
305
+ // async service({
306
+ // resourceName,
307
+ // bindingName,
308
+ // path,
309
+ // bindings = [],
310
+ // }: {
311
+ // resourceName: string
312
+ // bindingName?: string
313
+ // path?: string
314
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
315
+ // }) {
316
+ // return this.worker({
317
+ // resourceName: `${this.project}-${resourceName}-service-${this.environment}`,
318
+ // bindingName: this.composeBindingName({
319
+ // resource: 'service',
320
+ // bindingName,
321
+ // resourceName,
322
+ // }),
323
+ // path: `${path ?? `./services/${resourceName}`}`,
324
+ // bindings,
325
+ // })
326
+ // }
327
+ // // TODO: Add name
328
+ // async orchestrator({
329
+ // path,
330
+ // bindings = [],
331
+ // }: {
332
+ // path?: string
333
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
334
+ // }) {
335
+ // return this.worker({
336
+ // resourceName: `${this.project}-gateway-${this.environment}`,
337
+ // bindingName: 'GATEWAY',
338
+ // path: `${path ?? `./apps/gateway`}`,
339
+ // bindings,
340
+ // })
341
+ // }
217
342
  }
218
343
 
219
- const ENVIRONMENT = ["dev", "test", "staging", "production"];
220
-
221
- const validateEnvironment = (environment) => {
222
- if (ENVIRONMENT.includes(environment)) {
223
- return environment;
224
- }
225
- return Number(environment);
226
- };
227
-
228
344
  const ibanZodSchema = new z__namespace.$ZodString({
229
345
  type: "string",
230
346
  checks: [
@@ -398,7 +514,7 @@ const RPCResponse = {
398
514
  * @returns An `IRPCResponse<T>` with `null` data and the provided error.
399
515
  */
400
516
  serviceError(error) {
401
- consola.consola.error(error.message);
517
+ console.error(error.message);
402
518
  return {
403
519
  status: error.status,
404
520
  message: error.message,
@@ -853,15 +969,15 @@ function develitWorker(Worker) {
853
969
  }
854
970
 
855
971
  exports.DatabaseTransaction = DatabaseTransaction;
856
- exports.ENVIRONMENT = ENVIRONMENT;
857
972
  exports.Infrastructure = Infrastructure;
858
973
  exports.RPCResponse = RPCResponse;
859
974
  exports.action = action;
975
+ exports.bankAccount = bankAccount;
976
+ exports.bankAccountPostgres = bankAccountPostgres;
860
977
  exports.base = base;
861
978
  exports.basePostgres = basePostgres;
862
979
  exports.calculateExponentialBackoff = calculateExponentialBackoff;
863
980
  exports.cloudflareQueue = cloudflareQueue;
864
- exports.composeBindingName = composeBindingName;
865
981
  exports.createAuditLogWriter = createAuditLogWriter;
866
982
  exports.createInternalError = createInternalError;
867
983
  exports.defineCommand = defineCommand;
@@ -881,7 +997,6 @@ exports.handleAction = handleAction;
881
997
  exports.handleActionResponse = handleActionResponse;
882
998
  exports.ibanZodSchema = ibanZodSchema;
883
999
  exports.isInternalError = isInternalError;
884
- exports.loadWorkerConfig = loadWorkerConfig;
885
1000
  exports.paginationQuerySchema = paginationQuerySchema;
886
1001
  exports.paginationSchema = paginationSchema;
887
1002
  exports.service = service;
@@ -889,4 +1004,3 @@ exports.swiftZodSchema = swiftZodSchema;
889
1004
  exports.useResult = useResult;
890
1005
  exports.useResultSync = useResultSync;
891
1006
  exports.uuidv4 = uuidv4;
892
- exports.validateEnvironment = validateEnvironment;