@develit-io/backend-sdk 5.16.2 → 5.17.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
@@ -4,14 +4,16 @@ const drizzleOrm = require('drizzle-orm');
4
4
  const pgCore = require('drizzle-orm/pg-core');
5
5
  const sqliteCore = require('drizzle-orm/sqlite-core');
6
6
  const generalCodes = require('@develit-io/general-codes');
7
+ const commentJson = require('comment-json');
8
+ const node_fs = require('node:fs');
9
+ const path = require('@std/path');
7
10
  const text = require('@std/text');
8
11
  require('http-status-codes');
9
12
  const z = require('zod/v4/core');
10
13
  const h3 = require('h3');
11
14
  const fs = require('fs');
12
15
  const crypto$1 = require('node:crypto');
13
- const path = require('path');
14
- const commentJson = require('comment-json');
16
+ const path$1 = require('path');
15
17
  const superjson = require('superjson');
16
18
 
17
19
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -31,7 +33,7 @@ function _interopNamespaceCompat(e) {
31
33
  const z__namespace = /*#__PURE__*/_interopNamespaceCompat(z);
32
34
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
33
35
  const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto$1);
34
- const path__default = /*#__PURE__*/_interopDefaultCompat(path);
36
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path$1);
35
37
  const superjson__default = /*#__PURE__*/_interopDefaultCompat(superjson);
36
38
 
37
39
  const base = {
@@ -61,14 +63,100 @@ const bankAccount = {
61
63
  currency: sqliteCore.text("currency", { enum: generalCodes.CURRENCY_CODES }).notNull(),
62
64
  countryCode: sqliteCore.text("country_code", { enum: generalCodes.COUNTRY_CODES_2 }).notNull()
63
65
  };
66
+ const bankAccountCurrencyEnum = pgCore.pgEnum("currency", generalCodes.CURRENCY_CODES);
67
+ const bankAccountCountryCodeEnum = pgCore.pgEnum(
68
+ "country_code",
69
+ generalCodes.COUNTRY_CODES_2
70
+ );
71
+ const bankAccountBankCodeEnum = pgCore.pgEnum("bank_code", generalCodes.BANK_CODES);
64
72
  const bankAccountPostgres = {
65
73
  holderName: pgCore.text("holder_name").notNull(),
66
74
  number: pgCore.text("number").notNull(),
67
- bankCode: pgCore.pgEnum("bank_code", generalCodes.BANK_CODES)().notNull(),
75
+ bankCode: bankAccountBankCodeEnum().notNull(),
68
76
  iban: pgCore.text("iban").notNull(),
69
77
  bic: pgCore.text("bic").notNull(),
70
- currency: pgCore.pgEnum("currency", generalCodes.CURRENCY_CODES)().notNull(),
71
- countryCode: pgCore.pgEnum("country_code", generalCodes.COUNTRY_CODES_2)().notNull()
78
+ currency: bankAccountCurrencyEnum().notNull(),
79
+ countryCode: bankAccountCountryCodeEnum().notNull()
80
+ };
81
+
82
+ const composeD1Arguments = ({
83
+ resourceName
84
+ }) => {
85
+ return {
86
+ transform: {
87
+ database: {
88
+ name: resourceName,
89
+ primaryLocationHint: "weur"
90
+ }
91
+ }
92
+ };
93
+ };
94
+
95
+ const composeKvArguments = ({
96
+ resourceName
97
+ }) => {
98
+ return {
99
+ transform: {
100
+ namespace: {
101
+ title: resourceName
102
+ }
103
+ }
104
+ };
105
+ };
106
+
107
+ const composeQueueArguments = ({
108
+ resourceName,
109
+ deliveryDelay = 5,
110
+ messageRetentionPeriod = 259200
111
+ }) => {
112
+ return {
113
+ transform: {
114
+ queue: {
115
+ queueName: resourceName,
116
+ settings: {
117
+ deliveryDelay,
118
+ messageRetentionPeriod
119
+ }
120
+ }
121
+ }
122
+ };
123
+ };
124
+
125
+ const composeR2Arguments = ({
126
+ resourceName,
127
+ storageClass = "Standard"
128
+ }) => {
129
+ return {
130
+ transform: {
131
+ bucket: {
132
+ name: resourceName,
133
+ jurisdiction: "eu",
134
+ location: "weur",
135
+ storageClass
136
+ }
137
+ }
138
+ };
139
+ };
140
+
141
+ async function loadWorkerConfig({ path: path$1 }) {
142
+ const workerConfigFile = node_fs.readFileSync(path.join(path$1, "./wrangler.jsonc"), "utf-8");
143
+ return commentJson.parse(workerConfigFile);
144
+ }
145
+
146
+ const composeBindingName = ({
147
+ resource,
148
+ resourceName,
149
+ bindingName
150
+ }) => {
151
+ const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
152
+ return convertedBindingName.toUpperCase();
153
+ };
154
+ const composeResourceName = ({
155
+ project,
156
+ environment,
157
+ resourceName
158
+ }) => {
159
+ return `${project}-${resourceName}-${environment}`;
72
160
  };
73
161
 
74
162
  class Infrastructure {
@@ -84,158 +172,19 @@ class Infrastructure {
84
172
  this.environment = environment;
85
173
  this.sst = sst;
86
174
  }
87
- // TODO(Pookensivee): Make tests for this util
88
- composeBindingName({
89
- resource,
90
- resourceName,
91
- bindingName
92
- }) {
93
- const convertedBindingName = bindingName ? text.toSnakeCase(bindingName) : `${text.toSnakeCase(resourceName)}_${resource}`;
94
- return convertedBindingName.toUpperCase();
95
- }
96
- // TODO(Pookensivee): Make tests for this util
97
- composeResourceName({ resourceName }) {
98
- return `${this.project}-${resourceName}-${this.environment}`;
99
- }
100
- // TODO(Pookensivee): Make tests for this util
101
- composeKvArguments({ resourceName }) {
102
- return {
103
- transform: {
104
- namespace: {
105
- title: resourceName
106
- }
107
- }
108
- };
109
- }
110
- // TODO(Pookensivee): Make tests for this util
111
- composeD1Arguments({ resourceName }) {
112
- return {
113
- transform: {
114
- database: {
115
- name: resourceName,
116
- primaryLocationHint: "weur"
117
- }
118
- }
119
- };
120
- }
121
- // TODO(Pookensivee): Make tests for this util
122
- composeQueueArguments({
123
- resourceName,
124
- deliveryDelay = 5,
125
- messageRetentionPeriod = 259200
126
- }) {
127
- return {
128
- transform: {
129
- queue: {
130
- queueName: resourceName,
131
- settings: {
132
- deliveryDelay,
133
- messageRetentionPeriod
134
- }
135
- }
136
- }
137
- };
138
- }
139
- // TODO(Pookensivee): Make tests for this util
140
- composeR2Arguments({
141
- resourceName,
142
- storageClass = "Standard"
143
- }) {
144
- return {
145
- transform: {
146
- bucket: {
147
- name: resourceName,
148
- jurisdiction: "eu",
149
- location: "weur",
150
- storageClass
151
- }
152
- }
153
- };
154
- }
155
- // TODO: Solve the circular dependency on post infrastructure deploy script
156
- // TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
157
- // async composeWorkerArguments({
158
- // resourceName,
159
- // path,
160
- // bindings = [],
161
- // }: {
162
- // resourceName: string
163
- // path: string
164
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
165
- // }) {
166
- // const workerConfig = this.loadWorkerConfig({ path })
167
- // const environmentVariables = this.extractEnvironmentVariables({ workerConfigEnv:
168
- // workerConfig.env as WorkerConfigEnv
169
- // })
170
- // // TODO: Fix this
171
- // if (
172
- // 'SERVICE_CONFIG' in environmentVariables &&
173
- // typeof environmentVariables.SERVICE_CONFIG === 'object'
174
- // ) {
175
- // environmentVariables.SERVICE_CONFIG = JSON.stringify(environmentVariables.SERVICE_CONFIG)
176
- // }
177
- // // TODO: Fix this
178
- // if (
179
- // 'EMAIL_SENDER' in environmentVariables &&
180
- // typeof environmentVariables.EMAIL_SENDER === 'object'
181
- // ) {
182
- // environmentVariables.EMAIL_SENDER = JSON.stringify(environmentVariables.EMAIL_SENDER)
183
- // }
184
- // return {
185
- // handler: join(path, './src/index.ts'),
186
- // environment: Object.entries(environmentVariables).reduce((acc, [key, value]) => ({
187
- // ...acc,
188
- // [key]: String(value)
189
- // }), {} as Record<string, string>),
190
- // link: bindings,
191
- // transform: {
192
- // worker: {
193
- // scriptName: this.composeResourceName({ resourceName }),
194
- // compatibilityDate: '2025-06-04',
195
- // compatibilityFlags: ['nodejs_compat'],
196
- // observability: {
197
- // enabled: true,
198
- // headSamplingRate: 1,
199
- // logs: {
200
- // // Check whether this disables logs completely or just invocation ones
201
- // enabled: false,
202
- // invocationLogs: false,
203
- // },
204
- // },
205
- // },
206
- // }
207
- // } satisfies Partial<WorkerArgs>
208
- // }
209
- // loadWorkerConfig({ path }: { path: string }) {
210
- // const workerConfigFile = readFileSync(
211
- // join(path, './wrangler.jsonc'),
212
- // 'utf-8',
213
- // )
214
- // TODO: Use parse from comment-json
215
- // const jsonString = workerConfigFile
216
- // .replace(/\/\*[\s\S]*?\*\//g, '')
217
- // .replace(/\/\/.*$/gm, '')
218
- // return JSON.parse(jsonString)
219
- // }
220
- // extractEnvironmentVariables({
221
- // workerConfigEnv,
222
- // }: {
223
- // workerConfigEnv: WorkerConfigEnv
224
- // }) {
225
- // if (typeof this.environment === 'number') {
226
- // return { ...workerConfigEnv.dev.vars, ENVIRONMENT: this.environment }
227
- // }
228
- // return { ...workerConfigEnv[this.environment].vars }
229
- // }
230
175
  /**
231
176
  * Creates an instance of Cloudflare KV.
232
177
  */
233
178
  kv(options) {
234
179
  const { resourceName, bindingName } = options;
235
180
  return new this.sst.cloudflare.Kv(
236
- `${this.composeBindingName({ resource: "kv", resourceName, bindingName })}`,
237
- this.composeKvArguments({
238
- resourceName: this.composeResourceName({ resourceName })
181
+ `${composeBindingName({ resource: "kv", resourceName, bindingName })}`,
182
+ composeKvArguments({
183
+ resourceName: composeResourceName({
184
+ project: this.project,
185
+ environment: this.environment,
186
+ resourceName
187
+ })
239
188
  })
240
189
  );
241
190
  }
@@ -245,9 +194,13 @@ class Infrastructure {
245
194
  d1(options) {
246
195
  const { resourceName, bindingName } = options;
247
196
  return new this.sst.cloudflare.D1(
248
- `${this.composeBindingName({ resource: "d1", resourceName, bindingName })}`,
249
- this.composeD1Arguments({
250
- resourceName: this.composeResourceName({ resourceName })
197
+ `${composeBindingName({ resource: "d1", resourceName, bindingName })}`,
198
+ composeD1Arguments({
199
+ resourceName: composeResourceName({
200
+ project: this.project,
201
+ environment: this.environment,
202
+ resourceName
203
+ })
251
204
  })
252
205
  );
253
206
  }
@@ -257,9 +210,13 @@ class Infrastructure {
257
210
  queue(options) {
258
211
  const { resourceName, bindingName, deliveryDelay, messageRetentionPeriod } = options;
259
212
  return new this.sst.cloudflare.Queue(
260
- `${this.composeBindingName({ resource: "queue", resourceName, bindingName })}`,
261
- this.composeQueueArguments({
262
- resourceName: this.composeResourceName({ resourceName }),
213
+ `${composeBindingName({ resource: "queue", resourceName, bindingName })}`,
214
+ composeQueueArguments({
215
+ resourceName: composeResourceName({
216
+ project: this.project,
217
+ environment: this.environment,
218
+ resourceName
219
+ }),
263
220
  deliveryDelay,
264
221
  messageRetentionPeriod
265
222
  })
@@ -271,77 +228,28 @@ class Infrastructure {
271
228
  r2(options) {
272
229
  const { resourceName, bindingName, storageClass } = options;
273
230
  return new this.sst.cloudflare.Bucket(
274
- `${this.composeBindingName({ resource: "r2", resourceName, bindingName })}`,
275
- this.composeR2Arguments({
276
- resourceName: this.composeResourceName({ resourceName }),
231
+ `${composeBindingName({ resource: "r2", resourceName, bindingName })}`,
232
+ composeR2Arguments({
233
+ resourceName: composeResourceName({
234
+ project: this.project,
235
+ environment: this.environment,
236
+ resourceName
237
+ }),
277
238
  storageClass
278
239
  })
279
240
  );
280
241
  }
281
- // TODO: Solve the circular dependency on post infrastructure deploy script
282
- // async worker({
283
- // resourceName,
284
- // bindingName,
285
- // path,
286
- // bindings = [],
287
- // }: {
288
- // resourceName: string
289
- // bindingName: string
290
- // path: string
291
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
292
- // }) {
293
- // return new sst.cloudflare.Worker(
294
- // this.composeBindingName({
295
- // resource: 'worker',
296
- // bindingName,
297
- // resourceName,
298
- // }),
299
- // await this.composeWorkerArguments({
300
- // resourceName: this.composeResourceName({ resourceName }),
301
- // path,
302
- // bindings,
303
- // }),
304
- // )
305
- // }
306
- // async service({
307
- // resourceName,
308
- // bindingName,
309
- // path,
310
- // bindings = [],
311
- // }: {
312
- // resourceName: string
313
- // bindingName?: string
314
- // path?: string
315
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
316
- // }) {
317
- // return this.worker({
318
- // resourceName: `${this.project}-${resourceName}-service-${this.environment}`,
319
- // bindingName: this.composeBindingName({
320
- // resource: 'service',
321
- // bindingName,
322
- // resourceName,
323
- // }),
324
- // path: `${path ?? `./services/${resourceName}`}`,
325
- // bindings,
326
- // })
327
- // }
328
- // // TODO: Add name
329
- // async orchestrator({
330
- // path,
331
- // bindings = [],
332
- // }: {
333
- // path?: string
334
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
335
- // }) {
336
- // return this.worker({
337
- // resourceName: `${this.project}-gateway-${this.environment}`,
338
- // bindingName: 'GATEWAY',
339
- // path: `${path ?? `./apps/gateway`}`,
340
- // bindings,
341
- // })
342
- // }
343
242
  }
344
243
 
244
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
245
+
246
+ const validateEnvironment = (environment) => {
247
+ if (ENVIRONMENT.includes(environment)) {
248
+ return environment;
249
+ }
250
+ return Number(environment);
251
+ };
252
+
345
253
  const ibanZodSchema = new z__namespace.$ZodString({
346
254
  type: "string",
347
255
  checks: [
@@ -970,6 +878,7 @@ function develitWorker(Worker) {
970
878
  }
971
879
 
972
880
  exports.DatabaseTransaction = DatabaseTransaction;
881
+ exports.ENVIRONMENT = ENVIRONMENT;
973
882
  exports.Infrastructure = Infrastructure;
974
883
  exports.RPCResponse = RPCResponse;
975
884
  exports.action = action;
@@ -979,6 +888,7 @@ exports.base = base;
979
888
  exports.basePostgres = basePostgres;
980
889
  exports.calculateExponentialBackoff = calculateExponentialBackoff;
981
890
  exports.cloudflareQueue = cloudflareQueue;
891
+ exports.composeBindingName = composeBindingName;
982
892
  exports.createAuditLogWriter = createAuditLogWriter;
983
893
  exports.createInternalError = createInternalError;
984
894
  exports.defineCommand = defineCommand;
@@ -998,6 +908,7 @@ exports.handleAction = handleAction;
998
908
  exports.handleActionResponse = handleActionResponse;
999
909
  exports.ibanZodSchema = ibanZodSchema;
1000
910
  exports.isInternalError = isInternalError;
911
+ exports.loadWorkerConfig = loadWorkerConfig;
1001
912
  exports.paginationQuerySchema = paginationQuerySchema;
1002
913
  exports.paginationSchema = paginationSchema;
1003
914
  exports.service = service;
@@ -1005,3 +916,4 @@ exports.swiftZodSchema = swiftZodSchema;
1005
916
  exports.useResult = useResult;
1006
917
  exports.useResultSync = useResultSync;
1007
918
  exports.uuidv4 = uuidv4;
919
+ exports.validateEnvironment = validateEnvironment;
package/dist/index.d.cts CHANGED
@@ -4,6 +4,7 @@ import * as drizzle_orm from 'drizzle-orm';
4
4
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
5
5
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
6
6
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
7
+ import * as comment_json from 'comment-json';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
8
9
  export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
9
10
  import * as z from 'zod/v4/core';
@@ -45,8 +46,6 @@ declare const bankAccountPostgres: {
45
46
 
46
47
  type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
47
48
 
48
- type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
49
-
50
49
  type Environment = number | 'dev' | 'test' | 'staging' | 'production';
51
50
 
52
51
  interface SstInstance {
@@ -63,61 +62,6 @@ declare class Infrastructure {
63
62
  environment: Environment;
64
63
  sst: SstInstance;
65
64
  });
66
- composeBindingName({ resource, resourceName, bindingName, }: {
67
- resource: Resource;
68
- resourceName: string;
69
- bindingName?: string;
70
- }): string;
71
- composeResourceName({ resourceName }: {
72
- resourceName: string;
73
- }): string;
74
- composeKvArguments({ resourceName }: {
75
- resourceName: string;
76
- }): {
77
- transform: {
78
- namespace: {
79
- title: string;
80
- };
81
- };
82
- };
83
- composeD1Arguments({ resourceName }: {
84
- resourceName: string;
85
- }): {
86
- transform: {
87
- database: {
88
- name: string;
89
- primaryLocationHint: string;
90
- };
91
- };
92
- };
93
- composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
94
- resourceName: string;
95
- deliveryDelay?: number;
96
- messageRetentionPeriod?: number;
97
- }): {
98
- transform: {
99
- queue: {
100
- queueName: string;
101
- settings: {
102
- deliveryDelay: number;
103
- messageRetentionPeriod: number;
104
- };
105
- };
106
- };
107
- };
108
- composeR2Arguments({ resourceName, storageClass, }: {
109
- resourceName: string;
110
- storageClass?: 'Standard' | 'InfrequentAccess';
111
- }): {
112
- transform: {
113
- bucket: {
114
- name: string;
115
- jurisdiction: string;
116
- location: string;
117
- storageClass: "Standard" | "InfrequentAccess";
118
- };
119
- };
120
- };
121
65
  /**
122
66
  * Creates an instance of Cloudflare KV.
123
67
  */
@@ -184,6 +128,12 @@ declare class Infrastructure {
184
128
  }): any;
185
129
  }
186
130
 
131
+ declare function loadWorkerConfig({ path }: {
132
+ path: string;
133
+ }): Promise<comment_json.CommentJSONValue>;
134
+
135
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
136
+
187
137
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
188
138
  interface InternalError {
189
139
  status: InternalErrorResponseStatus;
@@ -246,6 +196,16 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
246
196
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
247
197
  }>>, z.$ZodObjectConfig>;
248
198
 
199
+ declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
200
+ resource: Resource;
201
+ resourceName: string;
202
+ bindingName?: string;
203
+ }) => string;
204
+
205
+ declare const validateEnvironment: (environment: string) => Environment;
206
+
207
+ declare const ENVIRONMENT: string[];
208
+
249
209
  declare const handleActionResponse: <T>({ error, status, message, data, }: {
250
210
  error: boolean;
251
211
  status: number;
@@ -566,5 +526,5 @@ interface WithRetryCounterOptions {
566
526
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
567
527
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
568
528
 
569
- export { DatabaseTransaction, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
529
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
570
530
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.mts CHANGED
@@ -4,6 +4,7 @@ import * as drizzle_orm from 'drizzle-orm';
4
4
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
5
5
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
6
6
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
7
+ import * as comment_json from 'comment-json';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
8
9
  export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
9
10
  import * as z from 'zod/v4/core';
@@ -45,8 +46,6 @@ declare const bankAccountPostgres: {
45
46
 
46
47
  type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
47
48
 
48
- type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
49
-
50
49
  type Environment = number | 'dev' | 'test' | 'staging' | 'production';
51
50
 
52
51
  interface SstInstance {
@@ -63,61 +62,6 @@ declare class Infrastructure {
63
62
  environment: Environment;
64
63
  sst: SstInstance;
65
64
  });
66
- composeBindingName({ resource, resourceName, bindingName, }: {
67
- resource: Resource;
68
- resourceName: string;
69
- bindingName?: string;
70
- }): string;
71
- composeResourceName({ resourceName }: {
72
- resourceName: string;
73
- }): string;
74
- composeKvArguments({ resourceName }: {
75
- resourceName: string;
76
- }): {
77
- transform: {
78
- namespace: {
79
- title: string;
80
- };
81
- };
82
- };
83
- composeD1Arguments({ resourceName }: {
84
- resourceName: string;
85
- }): {
86
- transform: {
87
- database: {
88
- name: string;
89
- primaryLocationHint: string;
90
- };
91
- };
92
- };
93
- composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
94
- resourceName: string;
95
- deliveryDelay?: number;
96
- messageRetentionPeriod?: number;
97
- }): {
98
- transform: {
99
- queue: {
100
- queueName: string;
101
- settings: {
102
- deliveryDelay: number;
103
- messageRetentionPeriod: number;
104
- };
105
- };
106
- };
107
- };
108
- composeR2Arguments({ resourceName, storageClass, }: {
109
- resourceName: string;
110
- storageClass?: 'Standard' | 'InfrequentAccess';
111
- }): {
112
- transform: {
113
- bucket: {
114
- name: string;
115
- jurisdiction: string;
116
- location: string;
117
- storageClass: "Standard" | "InfrequentAccess";
118
- };
119
- };
120
- };
121
65
  /**
122
66
  * Creates an instance of Cloudflare KV.
123
67
  */
@@ -184,6 +128,12 @@ declare class Infrastructure {
184
128
  }): any;
185
129
  }
186
130
 
131
+ declare function loadWorkerConfig({ path }: {
132
+ path: string;
133
+ }): Promise<comment_json.CommentJSONValue>;
134
+
135
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
136
+
187
137
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
188
138
  interface InternalError {
189
139
  status: InternalErrorResponseStatus;
@@ -246,6 +196,16 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
246
196
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
247
197
  }>>, z.$ZodObjectConfig>;
248
198
 
199
+ declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
200
+ resource: Resource;
201
+ resourceName: string;
202
+ bindingName?: string;
203
+ }) => string;
204
+
205
+ declare const validateEnvironment: (environment: string) => Environment;
206
+
207
+ declare const ENVIRONMENT: string[];
208
+
249
209
  declare const handleActionResponse: <T>({ error, status, message, data, }: {
250
210
  error: boolean;
251
211
  status: number;
@@ -566,5 +526,5 @@ interface WithRetryCounterOptions {
566
526
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
567
527
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
568
528
 
569
- export { DatabaseTransaction, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
529
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
570
530
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as drizzle_orm from 'drizzle-orm';
4
4
  import { ExtractTablesWithRelations, DBQueryConfig, BuildQueryResult } from 'drizzle-orm';
5
5
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
6
6
  import { AnySQLiteTable } from 'drizzle-orm/sqlite-core';
7
+ import * as comment_json from 'comment-json';
7
8
  import { StatusCodes, ReasonPhrases } from 'http-status-codes';
8
9
  export { ReasonPhrases as InternalResponsePhrase, StatusCodes as InternalResponseStatus } from 'http-status-codes';
9
10
  import * as z from 'zod/v4/core';
@@ -45,8 +46,6 @@ declare const bankAccountPostgres: {
45
46
 
46
47
  type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
47
48
 
48
- type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
49
-
50
49
  type Environment = number | 'dev' | 'test' | 'staging' | 'production';
51
50
 
52
51
  interface SstInstance {
@@ -63,61 +62,6 @@ declare class Infrastructure {
63
62
  environment: Environment;
64
63
  sst: SstInstance;
65
64
  });
66
- composeBindingName({ resource, resourceName, bindingName, }: {
67
- resource: Resource;
68
- resourceName: string;
69
- bindingName?: string;
70
- }): string;
71
- composeResourceName({ resourceName }: {
72
- resourceName: string;
73
- }): string;
74
- composeKvArguments({ resourceName }: {
75
- resourceName: string;
76
- }): {
77
- transform: {
78
- namespace: {
79
- title: string;
80
- };
81
- };
82
- };
83
- composeD1Arguments({ resourceName }: {
84
- resourceName: string;
85
- }): {
86
- transform: {
87
- database: {
88
- name: string;
89
- primaryLocationHint: string;
90
- };
91
- };
92
- };
93
- composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
94
- resourceName: string;
95
- deliveryDelay?: number;
96
- messageRetentionPeriod?: number;
97
- }): {
98
- transform: {
99
- queue: {
100
- queueName: string;
101
- settings: {
102
- deliveryDelay: number;
103
- messageRetentionPeriod: number;
104
- };
105
- };
106
- };
107
- };
108
- composeR2Arguments({ resourceName, storageClass, }: {
109
- resourceName: string;
110
- storageClass?: 'Standard' | 'InfrequentAccess';
111
- }): {
112
- transform: {
113
- bucket: {
114
- name: string;
115
- jurisdiction: string;
116
- location: string;
117
- storageClass: "Standard" | "InfrequentAccess";
118
- };
119
- };
120
- };
121
65
  /**
122
66
  * Creates an instance of Cloudflare KV.
123
67
  */
@@ -184,6 +128,12 @@ declare class Infrastructure {
184
128
  }): any;
185
129
  }
186
130
 
131
+ declare function loadWorkerConfig({ path }: {
132
+ path: string;
133
+ }): Promise<comment_json.CommentJSONValue>;
134
+
135
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
136
+
187
137
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
188
138
  interface InternalError {
189
139
  status: InternalErrorResponseStatus;
@@ -246,6 +196,16 @@ declare const paginationSchema: z.$ZodObject<Readonly<Readonly<{
246
196
  [k: string]: z.$ZodType<unknown, unknown, z.$ZodTypeInternals<unknown, unknown>>;
247
197
  }>>, z.$ZodObjectConfig>;
248
198
 
199
+ declare const composeBindingName: ({ resource, resourceName, bindingName, }: {
200
+ resource: Resource;
201
+ resourceName: string;
202
+ bindingName?: string;
203
+ }) => string;
204
+
205
+ declare const validateEnvironment: (environment: string) => Environment;
206
+
207
+ declare const ENVIRONMENT: string[];
208
+
249
209
  declare const handleActionResponse: <T>({ error, status, message, data, }: {
250
210
  error: boolean;
251
211
  status: number;
@@ -566,5 +526,5 @@ interface WithRetryCounterOptions {
566
526
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
567
527
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
568
528
 
569
- export { DatabaseTransaction, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
529
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
570
530
  export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.mjs CHANGED
@@ -2,6 +2,9 @@ import { sql } from 'drizzle-orm';
2
2
  import { timestamp, uuid, pgEnum, text as text$1 } from 'drizzle-orm/pg-core';
3
3
  import { integer, text } from 'drizzle-orm/sqlite-core';
4
4
  import { COUNTRY_CODES_2, CURRENCY_CODES, BANK_CODES } from '@develit-io/general-codes';
5
+ import { parse } from 'comment-json';
6
+ import { readFileSync } from 'node:fs';
7
+ import { join } from '@std/path';
5
8
  import { toSnakeCase } from '@std/text';
6
9
  import 'http-status-codes';
7
10
  import * as z from 'zod/v4/core';
@@ -9,7 +12,6 @@ import { createError } from 'h3';
9
12
  import fs from 'fs';
10
13
  import crypto$1 from 'node:crypto';
11
14
  import path from 'path';
12
- import { parse } from 'comment-json';
13
15
  import superjson from 'superjson';
14
16
 
15
17
  const base = {
@@ -39,14 +41,100 @@ const bankAccount = {
39
41
  currency: text("currency", { enum: CURRENCY_CODES }).notNull(),
40
42
  countryCode: text("country_code", { enum: COUNTRY_CODES_2 }).notNull()
41
43
  };
44
+ const bankAccountCurrencyEnum = pgEnum("currency", CURRENCY_CODES);
45
+ const bankAccountCountryCodeEnum = pgEnum(
46
+ "country_code",
47
+ COUNTRY_CODES_2
48
+ );
49
+ const bankAccountBankCodeEnum = pgEnum("bank_code", BANK_CODES);
42
50
  const bankAccountPostgres = {
43
51
  holderName: text$1("holder_name").notNull(),
44
52
  number: text$1("number").notNull(),
45
- bankCode: pgEnum("bank_code", BANK_CODES)().notNull(),
53
+ bankCode: bankAccountBankCodeEnum().notNull(),
46
54
  iban: text$1("iban").notNull(),
47
55
  bic: text$1("bic").notNull(),
48
- currency: pgEnum("currency", CURRENCY_CODES)().notNull(),
49
- countryCode: pgEnum("country_code", COUNTRY_CODES_2)().notNull()
56
+ currency: bankAccountCurrencyEnum().notNull(),
57
+ countryCode: bankAccountCountryCodeEnum().notNull()
58
+ };
59
+
60
+ const composeD1Arguments = ({
61
+ resourceName
62
+ }) => {
63
+ return {
64
+ transform: {
65
+ database: {
66
+ name: resourceName,
67
+ primaryLocationHint: "weur"
68
+ }
69
+ }
70
+ };
71
+ };
72
+
73
+ const composeKvArguments = ({
74
+ resourceName
75
+ }) => {
76
+ return {
77
+ transform: {
78
+ namespace: {
79
+ title: resourceName
80
+ }
81
+ }
82
+ };
83
+ };
84
+
85
+ const composeQueueArguments = ({
86
+ resourceName,
87
+ deliveryDelay = 5,
88
+ messageRetentionPeriod = 259200
89
+ }) => {
90
+ return {
91
+ transform: {
92
+ queue: {
93
+ queueName: resourceName,
94
+ settings: {
95
+ deliveryDelay,
96
+ messageRetentionPeriod
97
+ }
98
+ }
99
+ }
100
+ };
101
+ };
102
+
103
+ const composeR2Arguments = ({
104
+ resourceName,
105
+ storageClass = "Standard"
106
+ }) => {
107
+ return {
108
+ transform: {
109
+ bucket: {
110
+ name: resourceName,
111
+ jurisdiction: "eu",
112
+ location: "weur",
113
+ storageClass
114
+ }
115
+ }
116
+ };
117
+ };
118
+
119
+ async function loadWorkerConfig({ path }) {
120
+ const workerConfigFile = readFileSync(join(path, "./wrangler.jsonc"), "utf-8");
121
+ return parse(workerConfigFile);
122
+ }
123
+
124
+ const composeBindingName = ({
125
+ resource,
126
+ resourceName,
127
+ bindingName
128
+ }) => {
129
+ const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
130
+ return convertedBindingName.toUpperCase();
131
+ };
132
+ const composeResourceName = ({
133
+ project,
134
+ environment,
135
+ resourceName
136
+ }) => {
137
+ return `${project}-${resourceName}-${environment}`;
50
138
  };
51
139
 
52
140
  class Infrastructure {
@@ -62,158 +150,19 @@ class Infrastructure {
62
150
  this.environment = environment;
63
151
  this.sst = sst;
64
152
  }
65
- // TODO(Pookensivee): Make tests for this util
66
- composeBindingName({
67
- resource,
68
- resourceName,
69
- bindingName
70
- }) {
71
- const convertedBindingName = bindingName ? toSnakeCase(bindingName) : `${toSnakeCase(resourceName)}_${resource}`;
72
- return convertedBindingName.toUpperCase();
73
- }
74
- // TODO(Pookensivee): Make tests for this util
75
- composeResourceName({ resourceName }) {
76
- return `${this.project}-${resourceName}-${this.environment}`;
77
- }
78
- // TODO(Pookensivee): Make tests for this util
79
- composeKvArguments({ resourceName }) {
80
- return {
81
- transform: {
82
- namespace: {
83
- title: resourceName
84
- }
85
- }
86
- };
87
- }
88
- // TODO(Pookensivee): Make tests for this util
89
- composeD1Arguments({ resourceName }) {
90
- return {
91
- transform: {
92
- database: {
93
- name: resourceName,
94
- primaryLocationHint: "weur"
95
- }
96
- }
97
- };
98
- }
99
- // TODO(Pookensivee): Make tests for this util
100
- composeQueueArguments({
101
- resourceName,
102
- deliveryDelay = 5,
103
- messageRetentionPeriod = 259200
104
- }) {
105
- return {
106
- transform: {
107
- queue: {
108
- queueName: resourceName,
109
- settings: {
110
- deliveryDelay,
111
- messageRetentionPeriod
112
- }
113
- }
114
- }
115
- };
116
- }
117
- // TODO(Pookensivee): Make tests for this util
118
- composeR2Arguments({
119
- resourceName,
120
- storageClass = "Standard"
121
- }) {
122
- return {
123
- transform: {
124
- bucket: {
125
- name: resourceName,
126
- jurisdiction: "eu",
127
- location: "weur",
128
- storageClass
129
- }
130
- }
131
- };
132
- }
133
- // TODO: Solve the circular dependency on post infrastructure deploy script
134
- // TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
135
- // async composeWorkerArguments({
136
- // resourceName,
137
- // path,
138
- // bindings = [],
139
- // }: {
140
- // resourceName: string
141
- // path: string
142
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
143
- // }) {
144
- // const workerConfig = this.loadWorkerConfig({ path })
145
- // const environmentVariables = this.extractEnvironmentVariables({ workerConfigEnv:
146
- // workerConfig.env as WorkerConfigEnv
147
- // })
148
- // // TODO: Fix this
149
- // if (
150
- // 'SERVICE_CONFIG' in environmentVariables &&
151
- // typeof environmentVariables.SERVICE_CONFIG === 'object'
152
- // ) {
153
- // environmentVariables.SERVICE_CONFIG = JSON.stringify(environmentVariables.SERVICE_CONFIG)
154
- // }
155
- // // TODO: Fix this
156
- // if (
157
- // 'EMAIL_SENDER' in environmentVariables &&
158
- // typeof environmentVariables.EMAIL_SENDER === 'object'
159
- // ) {
160
- // environmentVariables.EMAIL_SENDER = JSON.stringify(environmentVariables.EMAIL_SENDER)
161
- // }
162
- // return {
163
- // handler: join(path, './src/index.ts'),
164
- // environment: Object.entries(environmentVariables).reduce((acc, [key, value]) => ({
165
- // ...acc,
166
- // [key]: String(value)
167
- // }), {} as Record<string, string>),
168
- // link: bindings,
169
- // transform: {
170
- // worker: {
171
- // scriptName: this.composeResourceName({ resourceName }),
172
- // compatibilityDate: '2025-06-04',
173
- // compatibilityFlags: ['nodejs_compat'],
174
- // observability: {
175
- // enabled: true,
176
- // headSamplingRate: 1,
177
- // logs: {
178
- // // Check whether this disables logs completely or just invocation ones
179
- // enabled: false,
180
- // invocationLogs: false,
181
- // },
182
- // },
183
- // },
184
- // }
185
- // } satisfies Partial<WorkerArgs>
186
- // }
187
- // loadWorkerConfig({ path }: { path: string }) {
188
- // const workerConfigFile = readFileSync(
189
- // join(path, './wrangler.jsonc'),
190
- // 'utf-8',
191
- // )
192
- // TODO: Use parse from comment-json
193
- // const jsonString = workerConfigFile
194
- // .replace(/\/\*[\s\S]*?\*\//g, '')
195
- // .replace(/\/\/.*$/gm, '')
196
- // return JSON.parse(jsonString)
197
- // }
198
- // extractEnvironmentVariables({
199
- // workerConfigEnv,
200
- // }: {
201
- // workerConfigEnv: WorkerConfigEnv
202
- // }) {
203
- // if (typeof this.environment === 'number') {
204
- // return { ...workerConfigEnv.dev.vars, ENVIRONMENT: this.environment }
205
- // }
206
- // return { ...workerConfigEnv[this.environment].vars }
207
- // }
208
153
  /**
209
154
  * Creates an instance of Cloudflare KV.
210
155
  */
211
156
  kv(options) {
212
157
  const { resourceName, bindingName } = options;
213
158
  return new this.sst.cloudflare.Kv(
214
- `${this.composeBindingName({ resource: "kv", resourceName, bindingName })}`,
215
- this.composeKvArguments({
216
- resourceName: this.composeResourceName({ resourceName })
159
+ `${composeBindingName({ resource: "kv", resourceName, bindingName })}`,
160
+ composeKvArguments({
161
+ resourceName: composeResourceName({
162
+ project: this.project,
163
+ environment: this.environment,
164
+ resourceName
165
+ })
217
166
  })
218
167
  );
219
168
  }
@@ -223,9 +172,13 @@ class Infrastructure {
223
172
  d1(options) {
224
173
  const { resourceName, bindingName } = options;
225
174
  return new this.sst.cloudflare.D1(
226
- `${this.composeBindingName({ resource: "d1", resourceName, bindingName })}`,
227
- this.composeD1Arguments({
228
- resourceName: this.composeResourceName({ resourceName })
175
+ `${composeBindingName({ resource: "d1", resourceName, bindingName })}`,
176
+ composeD1Arguments({
177
+ resourceName: composeResourceName({
178
+ project: this.project,
179
+ environment: this.environment,
180
+ resourceName
181
+ })
229
182
  })
230
183
  );
231
184
  }
@@ -235,9 +188,13 @@ class Infrastructure {
235
188
  queue(options) {
236
189
  const { resourceName, bindingName, deliveryDelay, messageRetentionPeriod } = options;
237
190
  return new this.sst.cloudflare.Queue(
238
- `${this.composeBindingName({ resource: "queue", resourceName, bindingName })}`,
239
- this.composeQueueArguments({
240
- resourceName: this.composeResourceName({ resourceName }),
191
+ `${composeBindingName({ resource: "queue", resourceName, bindingName })}`,
192
+ composeQueueArguments({
193
+ resourceName: composeResourceName({
194
+ project: this.project,
195
+ environment: this.environment,
196
+ resourceName
197
+ }),
241
198
  deliveryDelay,
242
199
  messageRetentionPeriod
243
200
  })
@@ -249,77 +206,28 @@ class Infrastructure {
249
206
  r2(options) {
250
207
  const { resourceName, bindingName, storageClass } = options;
251
208
  return new this.sst.cloudflare.Bucket(
252
- `${this.composeBindingName({ resource: "r2", resourceName, bindingName })}`,
253
- this.composeR2Arguments({
254
- resourceName: this.composeResourceName({ resourceName }),
209
+ `${composeBindingName({ resource: "r2", resourceName, bindingName })}`,
210
+ composeR2Arguments({
211
+ resourceName: composeResourceName({
212
+ project: this.project,
213
+ environment: this.environment,
214
+ resourceName
215
+ }),
255
216
  storageClass
256
217
  })
257
218
  );
258
219
  }
259
- // TODO: Solve the circular dependency on post infrastructure deploy script
260
- // async worker({
261
- // resourceName,
262
- // bindingName,
263
- // path,
264
- // bindings = [],
265
- // }: {
266
- // resourceName: string
267
- // bindingName: string
268
- // path: string
269
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
270
- // }) {
271
- // return new sst.cloudflare.Worker(
272
- // this.composeBindingName({
273
- // resource: 'worker',
274
- // bindingName,
275
- // resourceName,
276
- // }),
277
- // await this.composeWorkerArguments({
278
- // resourceName: this.composeResourceName({ resourceName }),
279
- // path,
280
- // bindings,
281
- // }),
282
- // )
283
- // }
284
- // async service({
285
- // resourceName,
286
- // bindingName,
287
- // path,
288
- // bindings = [],
289
- // }: {
290
- // resourceName: string
291
- // bindingName?: string
292
- // path?: string
293
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
294
- // }) {
295
- // return this.worker({
296
- // resourceName: `${this.project}-${resourceName}-service-${this.environment}`,
297
- // bindingName: this.composeBindingName({
298
- // resource: 'service',
299
- // bindingName,
300
- // resourceName,
301
- // }),
302
- // path: `${path ?? `./services/${resourceName}`}`,
303
- // bindings,
304
- // })
305
- // }
306
- // // TODO: Add name
307
- // async orchestrator({
308
- // path,
309
- // bindings = [],
310
- // }: {
311
- // path?: string
312
- // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
313
- // }) {
314
- // return this.worker({
315
- // resourceName: `${this.project}-gateway-${this.environment}`,
316
- // bindingName: 'GATEWAY',
317
- // path: `${path ?? `./apps/gateway`}`,
318
- // bindings,
319
- // })
320
- // }
321
220
  }
322
221
 
222
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
223
+
224
+ const validateEnvironment = (environment) => {
225
+ if (ENVIRONMENT.includes(environment)) {
226
+ return environment;
227
+ }
228
+ return Number(environment);
229
+ };
230
+
323
231
  const ibanZodSchema = new z.$ZodString({
324
232
  type: "string",
325
233
  checks: [
@@ -947,4 +855,4 @@ function develitWorker(Worker) {
947
855
  return DevelitWorker;
948
856
  }
949
857
 
950
- export { DatabaseTransaction, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4 };
858
+ export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, bankAccount, bankAccountPostgres, base, basePostgres, calculateExponentialBackoff, cloudflareQueue, composeBindingName, createAuditLogWriter, createInternalError, defineCommand, derivePortFromId, develitWorker, durableObjectNamespaceIdFromName, first, firstOrError, getD1Credentials, getD1DatabaseIdFromWrangler, getDrizzleD1Config, getDrizzlePgConfig, getPgCredentials, getPgDatabaseIdFromWrangler, getPgLocalConnectionString, handleAction, handleActionResponse, ibanZodSchema, isInternalError, loadWorkerConfig, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.16.2",
3
+ "version": "5.17.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
@@ -30,8 +30,8 @@
30
30
  "dist"
31
31
  ],
32
32
  "dependencies": {
33
- "@cloudflare/workers-types": "4.20250909.0",
34
- "@pulumi/cloudflare": "^6.8.0",
33
+ "@cloudflare/workers-types": "4.20250913.0",
34
+ "@pulumi/cloudflare": "^6.9.0",
35
35
  "@std/path": "npm:@jsr/std__path",
36
36
  "@std/text": "npm:@jsr/std__text",
37
37
  "comment-json": "^4.2.5",
@@ -42,8 +42,8 @@
42
42
  "superjson": "^2.2.2"
43
43
  },
44
44
  "peerDependencies": {
45
- "sst": "^3.17.12",
46
- "zod": "^4.1.5",
45
+ "sst": "^3.17.13",
46
+ "zod": "^4.1.8",
47
47
  "@develit-io/general-codes": "^1.11.0"
48
48
  }
49
49
  }