@develit-io/backend-sdk 5.13.0 → 5.14.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
@@ -51,6 +51,332 @@ const basePostgres = {
51
51
  }).default(drizzleOrm.sql`null`)
52
52
  };
53
53
 
54
+ // Copyright 2018-2025 the Deno authors. MIT license.
55
+ const CAPITALIZED_WORD_REGEXP = /\p{Lu}\p{Ll}+/u; // e.g. Apple
56
+ const ACRONYM_REGEXP = /\p{Lu}+(?=(\p{Lu}\p{Ll})|\P{L}|\b)/u; // e.g. ID, URL, handles an acronym followed by a capitalized word e.g. HTMLElement
57
+ const LOWERCASED_WORD_REGEXP = /(\p{Ll}+)/u; // e.g. apple
58
+ const ANY_LETTERS = /\p{L}+/u; // will match any sequence of letters, including in languages without a concept of upper/lower case
59
+ const DIGITS_REGEXP = /\p{N}+/u; // e.g. 123
60
+ const WORD_OR_NUMBER_REGEXP = new RegExp(`${CAPITALIZED_WORD_REGEXP.source}|${ACRONYM_REGEXP.source}|${LOWERCASED_WORD_REGEXP.source}|${ANY_LETTERS.source}|${DIGITS_REGEXP.source}`, "gu");
61
+ function splitToWords(input) {
62
+ return input.match(WORD_OR_NUMBER_REGEXP) ?? [];
63
+ }
64
+
65
+ // Copyright 2018-2025 the Deno authors. MIT license.
66
+ // This module is browser compatible.
67
+ /**
68
+ * Converts a string into snake_case.
69
+ *
70
+ * @example Usage
71
+ * ```ts
72
+ * import { toSnakeCase } from "@std/text/to-snake-case";
73
+ * import { assertEquals } from "@std/assert";
74
+ *
75
+ * assertEquals(toSnakeCase("deno is awesome"), "deno_is_awesome");
76
+ * ```
77
+ *
78
+ * @param input The string that is going to be converted into snake_case
79
+ * @returns The string as snake_case
80
+ */ function toSnakeCase(input) {
81
+ input = input.trim();
82
+ return splitToWords(input).join("_").toLowerCase();
83
+ }
84
+
85
+ class Infrastructure {
86
+ project;
87
+ environment;
88
+ sst;
89
+ constructor({
90
+ project,
91
+ environment,
92
+ sst
93
+ }) {
94
+ this.project = project;
95
+ this.environment = environment;
96
+ this.sst = sst;
97
+ }
98
+ // TODO(Pookensivee): Make tests for this util
99
+ composeBindingName({
100
+ resource,
101
+ resourceName,
102
+ bindingName
103
+ }) {
104
+ return bindingName ? toSnakeCase(bindingName.toUpperCase()) : `${toSnakeCase(resourceName.toUpperCase())}_${resource.toUpperCase()}`;
105
+ }
106
+ // TODO(Pookensivee): Make tests for this util
107
+ composeResourceName({ resourceName }) {
108
+ return `${this.project}-${resourceName}-${this.environment}`;
109
+ }
110
+ // TODO(Pookensivee): Make tests for this util
111
+ composeKvArguments({ resourceName }) {
112
+ return {
113
+ transform: {
114
+ namespace: {
115
+ title: resourceName
116
+ }
117
+ }
118
+ };
119
+ }
120
+ // TODO(Pookensivee): Make tests for this util
121
+ composeD1Arguments({ resourceName }) {
122
+ return {
123
+ transform: {
124
+ database: {
125
+ name: resourceName,
126
+ primaryLocationHint: "weur"
127
+ }
128
+ }
129
+ };
130
+ }
131
+ // TODO(Pookensivee): Make tests for this util
132
+ composeQueueArguments({
133
+ resourceName,
134
+ deliveryDelay = 5,
135
+ messageRetentionPeriod = 259200
136
+ }) {
137
+ return {
138
+ transform: {
139
+ queue: {
140
+ queueName: resourceName,
141
+ settings: {
142
+ deliveryDelay,
143
+ messageRetentionPeriod
144
+ }
145
+ }
146
+ }
147
+ };
148
+ }
149
+ // TODO(Pookensivee): Make tests for this util
150
+ composeR2Arguments({
151
+ resourceName,
152
+ storageClass = "Standard"
153
+ }) {
154
+ return {
155
+ transform: {
156
+ bucket: {
157
+ name: resourceName,
158
+ jurisdiction: "eu",
159
+ location: "weur",
160
+ storageClass
161
+ }
162
+ }
163
+ };
164
+ }
165
+ // TODO: Solve the circular dependency on post infra script
166
+ // TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
167
+ // async composeWorkerArguments({
168
+ // resourceName,
169
+ // path,
170
+ // bindings = [],
171
+ // }: {
172
+ // resourceName: string
173
+ // path: string
174
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
175
+ // }) {
176
+ // const workerConfig = this.loadWorkerConfig({ path })
177
+ // const environmentVariables = this.extractEnvironmentVariables({ workerConfigEnv:
178
+ // workerConfig.env as WorkerConfigEnv
179
+ // })
180
+ // // TODO: Fix this
181
+ // if (
182
+ // 'SERVICE_CONFIG' in environmentVariables &&
183
+ // typeof environmentVariables.SERVICE_CONFIG === 'object'
184
+ // ) {
185
+ // environmentVariables.SERVICE_CONFIG = JSON.stringify(environmentVariables.SERVICE_CONFIG)
186
+ // }
187
+ // // TODO: Fix this
188
+ // if (
189
+ // 'EMAIL_SENDER' in environmentVariables &&
190
+ // typeof environmentVariables.EMAIL_SENDER === 'object'
191
+ // ) {
192
+ // environmentVariables.EMAIL_SENDER = JSON.stringify(environmentVariables.EMAIL_SENDER)
193
+ // }
194
+ // return {
195
+ // handler: join(path, './src/index.ts'),
196
+ // environment: Object.entries(environmentVariables).reduce((acc, [key, value]) => ({
197
+ // ...acc,
198
+ // [key]: String(value)
199
+ // }), {} as Record<string, string>),
200
+ // link: bindings,
201
+ // transform: {
202
+ // worker: {
203
+ // scriptName: this.composeResourceName({ resourceName }),
204
+ // compatibilityDate: '2025-06-04',
205
+ // compatibilityFlags: ['nodejs_compat'],
206
+ // observability: {
207
+ // enabled: true,
208
+ // headSamplingRate: 1,
209
+ // logs: {
210
+ // // Check whether this disables logs completely or just invocation ones
211
+ // enabled: false,
212
+ // invocationLogs: false,
213
+ // },
214
+ // },
215
+ // },
216
+ // }
217
+ // } satisfies Partial<WorkerArgs>
218
+ // }
219
+ // loadWorkerConfig({ path }: { path: string }) {
220
+ // const workerConfigFile = readFileSync(
221
+ // join(path, './wrangler.jsonc'),
222
+ // 'utf-8',
223
+ // )
224
+ // const jsonString = workerConfigFile
225
+ // .replace(/\/\*[\s\S]*?\*\//g, '')
226
+ // .replace(/\/\/.*$/gm, '')
227
+ // return JSON.parse(jsonString)
228
+ // }
229
+ // extractEnvironmentVariables({
230
+ // workerConfigEnv,
231
+ // }: {
232
+ // workerConfigEnv: WorkerConfigEnv
233
+ // }) {
234
+ // if (typeof this.environment === 'number') {
235
+ // return { ...workerConfigEnv.dev.vars, ENVIRONMENT: this.environment }
236
+ // }
237
+ // return { ...workerConfigEnv[this.environment].vars }
238
+ // }
239
+ /**
240
+ * Creates an instance of Cloudflare KV.
241
+ * @param {Object} options - Configuration options for the KV instance.
242
+ * @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
243
+ * @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
244
+ * @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
245
+ */
246
+ kv({
247
+ resourceName,
248
+ bindingName
249
+ }) {
250
+ return new this.sst.cloudflare.Kv(
251
+ `${this.composeBindingName({ resource: "kv", resourceName, bindingName })}`,
252
+ this.composeKvArguments({
253
+ resourceName: this.composeResourceName({ resourceName })
254
+ })
255
+ );
256
+ }
257
+ /**
258
+ * Creates an instance of Cloudflare D1.
259
+ * @param {Object} options - Configuration options for the D1 instance.
260
+ * @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
261
+ * @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
262
+ * @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
263
+ */
264
+ d1({
265
+ resourceName,
266
+ bindingName
267
+ }) {
268
+ return new this.sst.cloudflare.D1(
269
+ `${this.composeBindingName({ resource: "d1", resourceName, bindingName })}`,
270
+ this.composeD1Arguments({
271
+ resourceName: this.composeResourceName({ resourceName })
272
+ })
273
+ );
274
+ }
275
+ /**
276
+ * Creates an instance of Cloudflare Queue.
277
+ * @param {Object} options - Configuration options for the Queue instance.
278
+ * @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
279
+ * @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
280
+ * @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
281
+ */
282
+ queue({
283
+ resourceName,
284
+ bindingName,
285
+ deliveryDelay,
286
+ messageRetentionPeriod
287
+ }) {
288
+ return new this.sst.cloudflare.Queue(
289
+ `${this.composeBindingName({ resource: "queue", resourceName, bindingName })}`,
290
+ this.composeQueueArguments({
291
+ resourceName: this.composeResourceName({ resourceName }),
292
+ deliveryDelay,
293
+ messageRetentionPeriod
294
+ })
295
+ );
296
+ }
297
+ /**
298
+ * Creates an instance of Cloudflare R2.
299
+ * @param {Object} options - Configuration options for the R2 instance.
300
+ * @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
301
+ * @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
302
+ * @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
303
+ */
304
+ r2({
305
+ resourceName,
306
+ bindingName,
307
+ storageClass
308
+ }) {
309
+ return new this.sst.cloudflare.Bucket(
310
+ `${this.composeBindingName({ resource: "r2", resourceName, bindingName })}`,
311
+ this.composeR2Arguments({
312
+ resourceName: this.composeResourceName({ resourceName }),
313
+ storageClass
314
+ })
315
+ );
316
+ }
317
+ // async worker({
318
+ // resourceName,
319
+ // bindingName,
320
+ // path,
321
+ // bindings = [],
322
+ // }: {
323
+ // resourceName: string
324
+ // bindingName: string
325
+ // path: string
326
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
327
+ // }) {
328
+ // return new sst.cloudflare.Worker(
329
+ // this.composeBindingName({
330
+ // resource: 'worker',
331
+ // bindingName,
332
+ // resourceName,
333
+ // }),
334
+ // await this.composeWorkerArguments({
335
+ // resourceName: this.composeResourceName({ resourceName }),
336
+ // path,
337
+ // bindings,
338
+ // }),
339
+ // )
340
+ // }
341
+ // async service({
342
+ // resourceName,
343
+ // bindingName,
344
+ // path,
345
+ // bindings = [],
346
+ // }: {
347
+ // resourceName: string
348
+ // bindingName?: string
349
+ // path?: string
350
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
351
+ // }) {
352
+ // return this.worker({
353
+ // resourceName: `${this.project}-${resourceName}-service-${this.environment}`,
354
+ // bindingName: this.composeBindingName({
355
+ // resource: 'service',
356
+ // bindingName,
357
+ // resourceName,
358
+ // }),
359
+ // path: `${path ?? `./services/${resourceName}`}`,
360
+ // bindings,
361
+ // })
362
+ // }
363
+ // // TODO: Add name
364
+ // async orchestrator({
365
+ // path,
366
+ // bindings = [],
367
+ // }: {
368
+ // path?: string
369
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
370
+ // }) {
371
+ // return this.worker({
372
+ // resourceName: `${this.project}-gateway-${this.environment}`,
373
+ // bindingName: 'GATEWAY',
374
+ // path: `${path ?? `./apps/gateway`}`,
375
+ // bindings,
376
+ // })
377
+ // }
378
+ }
379
+
54
380
  const ibanZodSchema = new z__namespace.$ZodString({
55
381
  type: "string",
56
382
  checks: [
@@ -679,6 +1005,7 @@ function develitWorker(Worker) {
679
1005
  }
680
1006
 
681
1007
  exports.DatabaseTransaction = DatabaseTransaction;
1008
+ exports.Infrastructure = Infrastructure;
682
1009
  exports.RPCResponse = RPCResponse;
683
1010
  exports.action = action;
684
1011
  exports.base = base;
package/dist/index.d.cts CHANGED
@@ -24,6 +24,155 @@ declare const basePostgres: {
24
24
  deletedAt: drizzle_orm.HasDefault<drizzle_orm_pg_core.PgTimestampBuilderInitial<"deleted_at">>;
25
25
  };
26
26
 
27
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
28
+
29
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
30
+
31
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
32
+
33
+ interface D1Component {
34
+ name?: string;
35
+ [key: string]: unknown;
36
+ }
37
+ interface KvComponent {
38
+ name?: string;
39
+ [key: string]: unknown;
40
+ }
41
+ interface QueueComponent {
42
+ url?: string;
43
+ [key: string]: unknown;
44
+ }
45
+ interface WorkerComponent {
46
+ url?: string;
47
+ [key: string]: unknown;
48
+ }
49
+ interface BucketComponent {
50
+ name?: string;
51
+ [key: string]: unknown;
52
+ }
53
+ interface SSTCloudflare {
54
+ Kv: new (name: string, args?: unknown) => KvComponent;
55
+ Worker: new (name: string, args: unknown) => WorkerComponent;
56
+ Bucket: new (name: string, args?: unknown) => BucketComponent;
57
+ D1: new (name: string, args?: unknown) => D1Component;
58
+ Queue: new (name: string, args?: unknown) => QueueComponent;
59
+ }
60
+ interface SSTContext {
61
+ cloudflare: SSTCloudflare;
62
+ }
63
+ declare class Infrastructure {
64
+ private project;
65
+ private environment;
66
+ private sst;
67
+ constructor({ project, environment, sst, }: {
68
+ project: Project;
69
+ environment: Environment;
70
+ sst: SSTContext;
71
+ });
72
+ composeBindingName({ resource, resourceName, bindingName, }: {
73
+ resource: Resource;
74
+ resourceName: string;
75
+ bindingName?: string;
76
+ }): string;
77
+ composeResourceName({ resourceName }: {
78
+ resourceName: string;
79
+ }): string;
80
+ composeKvArguments({ resourceName }: {
81
+ resourceName: string;
82
+ }): {
83
+ transform: {
84
+ namespace: {
85
+ title: string;
86
+ };
87
+ };
88
+ };
89
+ composeD1Arguments({ resourceName }: {
90
+ resourceName: string;
91
+ }): {
92
+ transform: {
93
+ database: {
94
+ name: string;
95
+ primaryLocationHint: string;
96
+ };
97
+ };
98
+ };
99
+ composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
100
+ resourceName: string;
101
+ deliveryDelay?: number;
102
+ messageRetentionPeriod?: number;
103
+ }): {
104
+ transform: {
105
+ queue: {
106
+ queueName: string;
107
+ settings: {
108
+ deliveryDelay: number;
109
+ messageRetentionPeriod: number;
110
+ };
111
+ };
112
+ };
113
+ };
114
+ composeR2Arguments({ resourceName, storageClass, }: {
115
+ resourceName: string;
116
+ storageClass?: 'Standard' | 'InfrequentAccess';
117
+ }): {
118
+ transform: {
119
+ bucket: {
120
+ name: string;
121
+ jurisdiction: string;
122
+ location: string;
123
+ storageClass: "Standard" | "InfrequentAccess";
124
+ };
125
+ };
126
+ };
127
+ /**
128
+ * Creates an instance of Cloudflare KV.
129
+ * @param {Object} options - Configuration options for the KV instance.
130
+ * @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
131
+ * @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
132
+ * @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
133
+ */
134
+ kv({ resourceName, bindingName, }: {
135
+ resourceName: string;
136
+ bindingName?: string;
137
+ }): KvComponent;
138
+ /**
139
+ * Creates an instance of Cloudflare D1.
140
+ * @param {Object} options - Configuration options for the D1 instance.
141
+ * @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
142
+ * @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
143
+ * @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
144
+ */
145
+ d1({ resourceName, bindingName, }: {
146
+ resourceName: string;
147
+ bindingName?: string;
148
+ }): D1Component;
149
+ /**
150
+ * Creates an instance of Cloudflare Queue.
151
+ * @param {Object} options - Configuration options for the Queue instance.
152
+ * @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
153
+ * @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
154
+ * @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
155
+ */
156
+ queue({ resourceName, bindingName, deliveryDelay, messageRetentionPeriod, }: {
157
+ resourceName: string;
158
+ bindingName?: string;
159
+ deliveryDelay?: number;
160
+ messageRetentionPeriod?: number;
161
+ }): QueueComponent;
162
+ /**
163
+ * Creates an instance of Cloudflare R2.
164
+ * @param {Object} options - Configuration options for the R2 instance.
165
+ * @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
166
+ * @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
167
+ * @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
168
+ */
169
+ r2({ resourceName, bindingName, storageClass, }: {
170
+ resourceName: string;
171
+ bindingName?: string;
172
+ storageClass?: 'Standard' | 'InfrequentAccess';
173
+ }): BucketComponent;
174
+ }
175
+
27
176
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
28
177
  interface InternalError {
29
178
  status: InternalErrorResponseStatus;
@@ -406,5 +555,5 @@ interface WithRetryCounterOptions {
406
555
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
407
556
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
408
557
 
409
- export { DatabaseTransaction, RPCResponse, action, 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 };
410
- export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, ValidatedInput };
558
+ export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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 };
559
+ export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.mts CHANGED
@@ -24,6 +24,155 @@ declare const basePostgres: {
24
24
  deletedAt: drizzle_orm.HasDefault<drizzle_orm_pg_core.PgTimestampBuilderInitial<"deleted_at">>;
25
25
  };
26
26
 
27
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
28
+
29
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
30
+
31
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
32
+
33
+ interface D1Component {
34
+ name?: string;
35
+ [key: string]: unknown;
36
+ }
37
+ interface KvComponent {
38
+ name?: string;
39
+ [key: string]: unknown;
40
+ }
41
+ interface QueueComponent {
42
+ url?: string;
43
+ [key: string]: unknown;
44
+ }
45
+ interface WorkerComponent {
46
+ url?: string;
47
+ [key: string]: unknown;
48
+ }
49
+ interface BucketComponent {
50
+ name?: string;
51
+ [key: string]: unknown;
52
+ }
53
+ interface SSTCloudflare {
54
+ Kv: new (name: string, args?: unknown) => KvComponent;
55
+ Worker: new (name: string, args: unknown) => WorkerComponent;
56
+ Bucket: new (name: string, args?: unknown) => BucketComponent;
57
+ D1: new (name: string, args?: unknown) => D1Component;
58
+ Queue: new (name: string, args?: unknown) => QueueComponent;
59
+ }
60
+ interface SSTContext {
61
+ cloudflare: SSTCloudflare;
62
+ }
63
+ declare class Infrastructure {
64
+ private project;
65
+ private environment;
66
+ private sst;
67
+ constructor({ project, environment, sst, }: {
68
+ project: Project;
69
+ environment: Environment;
70
+ sst: SSTContext;
71
+ });
72
+ composeBindingName({ resource, resourceName, bindingName, }: {
73
+ resource: Resource;
74
+ resourceName: string;
75
+ bindingName?: string;
76
+ }): string;
77
+ composeResourceName({ resourceName }: {
78
+ resourceName: string;
79
+ }): string;
80
+ composeKvArguments({ resourceName }: {
81
+ resourceName: string;
82
+ }): {
83
+ transform: {
84
+ namespace: {
85
+ title: string;
86
+ };
87
+ };
88
+ };
89
+ composeD1Arguments({ resourceName }: {
90
+ resourceName: string;
91
+ }): {
92
+ transform: {
93
+ database: {
94
+ name: string;
95
+ primaryLocationHint: string;
96
+ };
97
+ };
98
+ };
99
+ composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
100
+ resourceName: string;
101
+ deliveryDelay?: number;
102
+ messageRetentionPeriod?: number;
103
+ }): {
104
+ transform: {
105
+ queue: {
106
+ queueName: string;
107
+ settings: {
108
+ deliveryDelay: number;
109
+ messageRetentionPeriod: number;
110
+ };
111
+ };
112
+ };
113
+ };
114
+ composeR2Arguments({ resourceName, storageClass, }: {
115
+ resourceName: string;
116
+ storageClass?: 'Standard' | 'InfrequentAccess';
117
+ }): {
118
+ transform: {
119
+ bucket: {
120
+ name: string;
121
+ jurisdiction: string;
122
+ location: string;
123
+ storageClass: "Standard" | "InfrequentAccess";
124
+ };
125
+ };
126
+ };
127
+ /**
128
+ * Creates an instance of Cloudflare KV.
129
+ * @param {Object} options - Configuration options for the KV instance.
130
+ * @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
131
+ * @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
132
+ * @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
133
+ */
134
+ kv({ resourceName, bindingName, }: {
135
+ resourceName: string;
136
+ bindingName?: string;
137
+ }): KvComponent;
138
+ /**
139
+ * Creates an instance of Cloudflare D1.
140
+ * @param {Object} options - Configuration options for the D1 instance.
141
+ * @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
142
+ * @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
143
+ * @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
144
+ */
145
+ d1({ resourceName, bindingName, }: {
146
+ resourceName: string;
147
+ bindingName?: string;
148
+ }): D1Component;
149
+ /**
150
+ * Creates an instance of Cloudflare Queue.
151
+ * @param {Object} options - Configuration options for the Queue instance.
152
+ * @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
153
+ * @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
154
+ * @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
155
+ */
156
+ queue({ resourceName, bindingName, deliveryDelay, messageRetentionPeriod, }: {
157
+ resourceName: string;
158
+ bindingName?: string;
159
+ deliveryDelay?: number;
160
+ messageRetentionPeriod?: number;
161
+ }): QueueComponent;
162
+ /**
163
+ * Creates an instance of Cloudflare R2.
164
+ * @param {Object} options - Configuration options for the R2 instance.
165
+ * @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
166
+ * @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
167
+ * @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
168
+ */
169
+ r2({ resourceName, bindingName, storageClass, }: {
170
+ resourceName: string;
171
+ bindingName?: string;
172
+ storageClass?: 'Standard' | 'InfrequentAccess';
173
+ }): BucketComponent;
174
+ }
175
+
27
176
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
28
177
  interface InternalError {
29
178
  status: InternalErrorResponseStatus;
@@ -406,5 +555,5 @@ interface WithRetryCounterOptions {
406
555
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
407
556
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
408
557
 
409
- export { DatabaseTransaction, RPCResponse, action, 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 };
410
- export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, ValidatedInput };
558
+ export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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 };
559
+ export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,155 @@ declare const basePostgres: {
24
24
  deletedAt: drizzle_orm.HasDefault<drizzle_orm_pg_core.PgTimestampBuilderInitial<"deleted_at">>;
25
25
  };
26
26
 
27
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'txs';
28
+
29
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
30
+
31
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
32
+
33
+ interface D1Component {
34
+ name?: string;
35
+ [key: string]: unknown;
36
+ }
37
+ interface KvComponent {
38
+ name?: string;
39
+ [key: string]: unknown;
40
+ }
41
+ interface QueueComponent {
42
+ url?: string;
43
+ [key: string]: unknown;
44
+ }
45
+ interface WorkerComponent {
46
+ url?: string;
47
+ [key: string]: unknown;
48
+ }
49
+ interface BucketComponent {
50
+ name?: string;
51
+ [key: string]: unknown;
52
+ }
53
+ interface SSTCloudflare {
54
+ Kv: new (name: string, args?: unknown) => KvComponent;
55
+ Worker: new (name: string, args: unknown) => WorkerComponent;
56
+ Bucket: new (name: string, args?: unknown) => BucketComponent;
57
+ D1: new (name: string, args?: unknown) => D1Component;
58
+ Queue: new (name: string, args?: unknown) => QueueComponent;
59
+ }
60
+ interface SSTContext {
61
+ cloudflare: SSTCloudflare;
62
+ }
63
+ declare class Infrastructure {
64
+ private project;
65
+ private environment;
66
+ private sst;
67
+ constructor({ project, environment, sst, }: {
68
+ project: Project;
69
+ environment: Environment;
70
+ sst: SSTContext;
71
+ });
72
+ composeBindingName({ resource, resourceName, bindingName, }: {
73
+ resource: Resource;
74
+ resourceName: string;
75
+ bindingName?: string;
76
+ }): string;
77
+ composeResourceName({ resourceName }: {
78
+ resourceName: string;
79
+ }): string;
80
+ composeKvArguments({ resourceName }: {
81
+ resourceName: string;
82
+ }): {
83
+ transform: {
84
+ namespace: {
85
+ title: string;
86
+ };
87
+ };
88
+ };
89
+ composeD1Arguments({ resourceName }: {
90
+ resourceName: string;
91
+ }): {
92
+ transform: {
93
+ database: {
94
+ name: string;
95
+ primaryLocationHint: string;
96
+ };
97
+ };
98
+ };
99
+ composeQueueArguments({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
100
+ resourceName: string;
101
+ deliveryDelay?: number;
102
+ messageRetentionPeriod?: number;
103
+ }): {
104
+ transform: {
105
+ queue: {
106
+ queueName: string;
107
+ settings: {
108
+ deliveryDelay: number;
109
+ messageRetentionPeriod: number;
110
+ };
111
+ };
112
+ };
113
+ };
114
+ composeR2Arguments({ resourceName, storageClass, }: {
115
+ resourceName: string;
116
+ storageClass?: 'Standard' | 'InfrequentAccess';
117
+ }): {
118
+ transform: {
119
+ bucket: {
120
+ name: string;
121
+ jurisdiction: string;
122
+ location: string;
123
+ storageClass: "Standard" | "InfrequentAccess";
124
+ };
125
+ };
126
+ };
127
+ /**
128
+ * Creates an instance of Cloudflare KV.
129
+ * @param {Object} options - Configuration options for the KV instance.
130
+ * @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
131
+ * @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
132
+ * @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
133
+ */
134
+ kv({ resourceName, bindingName, }: {
135
+ resourceName: string;
136
+ bindingName?: string;
137
+ }): KvComponent;
138
+ /**
139
+ * Creates an instance of Cloudflare D1.
140
+ * @param {Object} options - Configuration options for the D1 instance.
141
+ * @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
142
+ * @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
143
+ * @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
144
+ */
145
+ d1({ resourceName, bindingName, }: {
146
+ resourceName: string;
147
+ bindingName?: string;
148
+ }): D1Component;
149
+ /**
150
+ * Creates an instance of Cloudflare Queue.
151
+ * @param {Object} options - Configuration options for the Queue instance.
152
+ * @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
153
+ * @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
154
+ * @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
155
+ */
156
+ queue({ resourceName, bindingName, deliveryDelay, messageRetentionPeriod, }: {
157
+ resourceName: string;
158
+ bindingName?: string;
159
+ deliveryDelay?: number;
160
+ messageRetentionPeriod?: number;
161
+ }): QueueComponent;
162
+ /**
163
+ * Creates an instance of Cloudflare R2.
164
+ * @param {Object} options - Configuration options for the R2 instance.
165
+ * @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
166
+ * @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
167
+ * @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
168
+ */
169
+ r2({ resourceName, bindingName, storageClass, }: {
170
+ resourceName: string;
171
+ bindingName?: string;
172
+ storageClass?: 'Standard' | 'InfrequentAccess';
173
+ }): BucketComponent;
174
+ }
175
+
27
176
  type InternalErrorResponseStatus = Exclude<StatusCodes, 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207>;
28
177
  interface InternalError {
29
178
  status: InternalErrorResponseStatus;
@@ -406,5 +555,5 @@ interface WithRetryCounterOptions {
406
555
  type AsyncMethod<TArgs extends unknown[] = unknown[], TResult = unknown> = (...args: TArgs) => Promise<TResult>;
407
556
  declare function cloudflareQueue<TArgs extends unknown[] = unknown[], TResult = unknown>(options: WithRetryCounterOptions): (target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AsyncMethod<TArgs, TResult>>) => void;
408
557
 
409
- export { DatabaseTransaction, RPCResponse, action, 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 };
410
- export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, ValidatedInput };
558
+ export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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 };
559
+ export type { ActionExecution, ActionHandlerOptions, AuditLogWriter, Command, CommandLogPayload, DevelitWorkerMethods, Environment, GatewayResponse, IRPCResponse, IncludeRelation, InferResultType, InternalError, InternalErrorResponseStatus, Project, ValidatedInput };
package/dist/index.mjs CHANGED
@@ -29,6 +29,332 @@ const basePostgres = {
29
29
  }).default(sql`null`)
30
30
  };
31
31
 
32
+ // Copyright 2018-2025 the Deno authors. MIT license.
33
+ const CAPITALIZED_WORD_REGEXP = /\p{Lu}\p{Ll}+/u; // e.g. Apple
34
+ const ACRONYM_REGEXP = /\p{Lu}+(?=(\p{Lu}\p{Ll})|\P{L}|\b)/u; // e.g. ID, URL, handles an acronym followed by a capitalized word e.g. HTMLElement
35
+ const LOWERCASED_WORD_REGEXP = /(\p{Ll}+)/u; // e.g. apple
36
+ const ANY_LETTERS = /\p{L}+/u; // will match any sequence of letters, including in languages without a concept of upper/lower case
37
+ const DIGITS_REGEXP = /\p{N}+/u; // e.g. 123
38
+ const WORD_OR_NUMBER_REGEXP = new RegExp(`${CAPITALIZED_WORD_REGEXP.source}|${ACRONYM_REGEXP.source}|${LOWERCASED_WORD_REGEXP.source}|${ANY_LETTERS.source}|${DIGITS_REGEXP.source}`, "gu");
39
+ function splitToWords(input) {
40
+ return input.match(WORD_OR_NUMBER_REGEXP) ?? [];
41
+ }
42
+
43
+ // Copyright 2018-2025 the Deno authors. MIT license.
44
+ // This module is browser compatible.
45
+ /**
46
+ * Converts a string into snake_case.
47
+ *
48
+ * @example Usage
49
+ * ```ts
50
+ * import { toSnakeCase } from "@std/text/to-snake-case";
51
+ * import { assertEquals } from "@std/assert";
52
+ *
53
+ * assertEquals(toSnakeCase("deno is awesome"), "deno_is_awesome");
54
+ * ```
55
+ *
56
+ * @param input The string that is going to be converted into snake_case
57
+ * @returns The string as snake_case
58
+ */ function toSnakeCase(input) {
59
+ input = input.trim();
60
+ return splitToWords(input).join("_").toLowerCase();
61
+ }
62
+
63
+ class Infrastructure {
64
+ project;
65
+ environment;
66
+ sst;
67
+ constructor({
68
+ project,
69
+ environment,
70
+ sst
71
+ }) {
72
+ this.project = project;
73
+ this.environment = environment;
74
+ this.sst = sst;
75
+ }
76
+ // TODO(Pookensivee): Make tests for this util
77
+ composeBindingName({
78
+ resource,
79
+ resourceName,
80
+ bindingName
81
+ }) {
82
+ return bindingName ? toSnakeCase(bindingName.toUpperCase()) : `${toSnakeCase(resourceName.toUpperCase())}_${resource.toUpperCase()}`;
83
+ }
84
+ // TODO(Pookensivee): Make tests for this util
85
+ composeResourceName({ resourceName }) {
86
+ return `${this.project}-${resourceName}-${this.environment}`;
87
+ }
88
+ // TODO(Pookensivee): Make tests for this util
89
+ composeKvArguments({ resourceName }) {
90
+ return {
91
+ transform: {
92
+ namespace: {
93
+ title: resourceName
94
+ }
95
+ }
96
+ };
97
+ }
98
+ // TODO(Pookensivee): Make tests for this util
99
+ composeD1Arguments({ resourceName }) {
100
+ return {
101
+ transform: {
102
+ database: {
103
+ name: resourceName,
104
+ primaryLocationHint: "weur"
105
+ }
106
+ }
107
+ };
108
+ }
109
+ // TODO(Pookensivee): Make tests for this util
110
+ composeQueueArguments({
111
+ resourceName,
112
+ deliveryDelay = 5,
113
+ messageRetentionPeriod = 259200
114
+ }) {
115
+ return {
116
+ transform: {
117
+ queue: {
118
+ queueName: resourceName,
119
+ settings: {
120
+ deliveryDelay,
121
+ messageRetentionPeriod
122
+ }
123
+ }
124
+ }
125
+ };
126
+ }
127
+ // TODO(Pookensivee): Make tests for this util
128
+ composeR2Arguments({
129
+ resourceName,
130
+ storageClass = "Standard"
131
+ }) {
132
+ return {
133
+ transform: {
134
+ bucket: {
135
+ name: resourceName,
136
+ jurisdiction: "eu",
137
+ location: "weur",
138
+ storageClass
139
+ }
140
+ }
141
+ };
142
+ }
143
+ // TODO: Solve the circular dependency on post infra script
144
+ // TODO: Cannot assign a queue as a producer, work around: https://developers.cloudflare.com/workers/wrangler/commands/#queues-consumer-add-script-name
145
+ // async composeWorkerArguments({
146
+ // resourceName,
147
+ // path,
148
+ // bindings = [],
149
+ // }: {
150
+ // resourceName: string
151
+ // path: string
152
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
153
+ // }) {
154
+ // const workerConfig = this.loadWorkerConfig({ path })
155
+ // const environmentVariables = this.extractEnvironmentVariables({ workerConfigEnv:
156
+ // workerConfig.env as WorkerConfigEnv
157
+ // })
158
+ // // TODO: Fix this
159
+ // if (
160
+ // 'SERVICE_CONFIG' in environmentVariables &&
161
+ // typeof environmentVariables.SERVICE_CONFIG === 'object'
162
+ // ) {
163
+ // environmentVariables.SERVICE_CONFIG = JSON.stringify(environmentVariables.SERVICE_CONFIG)
164
+ // }
165
+ // // TODO: Fix this
166
+ // if (
167
+ // 'EMAIL_SENDER' in environmentVariables &&
168
+ // typeof environmentVariables.EMAIL_SENDER === 'object'
169
+ // ) {
170
+ // environmentVariables.EMAIL_SENDER = JSON.stringify(environmentVariables.EMAIL_SENDER)
171
+ // }
172
+ // return {
173
+ // handler: join(path, './src/index.ts'),
174
+ // environment: Object.entries(environmentVariables).reduce((acc, [key, value]) => ({
175
+ // ...acc,
176
+ // [key]: String(value)
177
+ // }), {} as Record<string, string>),
178
+ // link: bindings,
179
+ // transform: {
180
+ // worker: {
181
+ // scriptName: this.composeResourceName({ resourceName }),
182
+ // compatibilityDate: '2025-06-04',
183
+ // compatibilityFlags: ['nodejs_compat'],
184
+ // observability: {
185
+ // enabled: true,
186
+ // headSamplingRate: 1,
187
+ // logs: {
188
+ // // Check whether this disables logs completely or just invocation ones
189
+ // enabled: false,
190
+ // invocationLogs: false,
191
+ // },
192
+ // },
193
+ // },
194
+ // }
195
+ // } satisfies Partial<WorkerArgs>
196
+ // }
197
+ // loadWorkerConfig({ path }: { path: string }) {
198
+ // const workerConfigFile = readFileSync(
199
+ // join(path, './wrangler.jsonc'),
200
+ // 'utf-8',
201
+ // )
202
+ // const jsonString = workerConfigFile
203
+ // .replace(/\/\*[\s\S]*?\*\//g, '')
204
+ // .replace(/\/\/.*$/gm, '')
205
+ // return JSON.parse(jsonString)
206
+ // }
207
+ // extractEnvironmentVariables({
208
+ // workerConfigEnv,
209
+ // }: {
210
+ // workerConfigEnv: WorkerConfigEnv
211
+ // }) {
212
+ // if (typeof this.environment === 'number') {
213
+ // return { ...workerConfigEnv.dev.vars, ENVIRONMENT: this.environment }
214
+ // }
215
+ // return { ...workerConfigEnv[this.environment].vars }
216
+ // }
217
+ /**
218
+ * Creates an instance of Cloudflare KV.
219
+ * @param {Object} options - Configuration options for the KV instance.
220
+ * @param {string} options.name - Name of the KV. Do not include 'kv' prefix.
221
+ * @param {string?} options.bindingName - Name of the KV's binding. If not set then it's generated automatically based on the provided name.
222
+ * @returns {sst.cloudflare.Kv} An instance of Cloudflare KV.
223
+ */
224
+ kv({
225
+ resourceName,
226
+ bindingName
227
+ }) {
228
+ return new this.sst.cloudflare.Kv(
229
+ `${this.composeBindingName({ resource: "kv", resourceName, bindingName })}`,
230
+ this.composeKvArguments({
231
+ resourceName: this.composeResourceName({ resourceName })
232
+ })
233
+ );
234
+ }
235
+ /**
236
+ * Creates an instance of Cloudflare D1.
237
+ * @param {Object} options - Configuration options for the D1 instance.
238
+ * @param {string} options.name - Name of the D1. Do not include 'd1' prefix.
239
+ * @param {string?} options.bindingName - Name of the D1's binding. If not set then it's generated automatically based on the provided name.
240
+ * @returns {sst.cloudflare.D1} An instance of Cloudflare D1.
241
+ */
242
+ d1({
243
+ resourceName,
244
+ bindingName
245
+ }) {
246
+ return new this.sst.cloudflare.D1(
247
+ `${this.composeBindingName({ resource: "d1", resourceName, bindingName })}`,
248
+ this.composeD1Arguments({
249
+ resourceName: this.composeResourceName({ resourceName })
250
+ })
251
+ );
252
+ }
253
+ /**
254
+ * Creates an instance of Cloudflare Queue.
255
+ * @param {Object} options - Configuration options for the Queue instance.
256
+ * @param {string} options.name - Name of the Queue. Do not include 'queue' prefix.
257
+ * @param {string?} options.bindingName - Name of the Queue's binding. If not set then it's generated automatically based on the provided name.
258
+ * @returns {sst.cloudflare.Queue} An instance of Cloudflare Queue.
259
+ */
260
+ queue({
261
+ resourceName,
262
+ bindingName,
263
+ deliveryDelay,
264
+ messageRetentionPeriod
265
+ }) {
266
+ return new this.sst.cloudflare.Queue(
267
+ `${this.composeBindingName({ resource: "queue", resourceName, bindingName })}`,
268
+ this.composeQueueArguments({
269
+ resourceName: this.composeResourceName({ resourceName }),
270
+ deliveryDelay,
271
+ messageRetentionPeriod
272
+ })
273
+ );
274
+ }
275
+ /**
276
+ * Creates an instance of Cloudflare R2.
277
+ * @param {Object} options - Configuration options for the R2 instance.
278
+ * @param {string} options.name - Name of the R2. Do not include 'r2' prefix.
279
+ * @param {string?} options.bindingName - Name of the R2's binding. If not set then it's generated automatically based on the provided name.
280
+ * @returns {sst.cloudflare.Bucket} An instance of Cloudflare R2.
281
+ */
282
+ r2({
283
+ resourceName,
284
+ bindingName,
285
+ storageClass
286
+ }) {
287
+ return new this.sst.cloudflare.Bucket(
288
+ `${this.composeBindingName({ resource: "r2", resourceName, bindingName })}`,
289
+ this.composeR2Arguments({
290
+ resourceName: this.composeResourceName({ resourceName }),
291
+ storageClass
292
+ })
293
+ );
294
+ }
295
+ // async worker({
296
+ // resourceName,
297
+ // bindingName,
298
+ // path,
299
+ // bindings = [],
300
+ // }: {
301
+ // resourceName: string
302
+ // bindingName: string
303
+ // path: string
304
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
305
+ // }) {
306
+ // return new sst.cloudflare.Worker(
307
+ // this.composeBindingName({
308
+ // resource: 'worker',
309
+ // bindingName,
310
+ // resourceName,
311
+ // }),
312
+ // await this.composeWorkerArguments({
313
+ // resourceName: this.composeResourceName({ resourceName }),
314
+ // path,
315
+ // bindings,
316
+ // }),
317
+ // )
318
+ // }
319
+ // async service({
320
+ // resourceName,
321
+ // bindingName,
322
+ // path,
323
+ // bindings = [],
324
+ // }: {
325
+ // resourceName: string
326
+ // bindingName?: string
327
+ // path?: string
328
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
329
+ // }) {
330
+ // return this.worker({
331
+ // resourceName: `${this.project}-${resourceName}-service-${this.environment}`,
332
+ // bindingName: this.composeBindingName({
333
+ // resource: 'service',
334
+ // bindingName,
335
+ // resourceName,
336
+ // }),
337
+ // path: `${path ?? `./services/${resourceName}`}`,
338
+ // bindings,
339
+ // })
340
+ // }
341
+ // // TODO: Add name
342
+ // async orchestrator({
343
+ // path,
344
+ // bindings = [],
345
+ // }: {
346
+ // path?: string
347
+ // bindings?: Input<Kv | D1 | Queue | Worker | Bucket>[]
348
+ // }) {
349
+ // return this.worker({
350
+ // resourceName: `${this.project}-gateway-${this.environment}`,
351
+ // bindingName: 'GATEWAY',
352
+ // path: `${path ?? `./apps/gateway`}`,
353
+ // bindings,
354
+ // })
355
+ // }
356
+ }
357
+
32
358
  const ibanZodSchema = new z.$ZodString({
33
359
  type: "string",
34
360
  checks: [
@@ -656,4 +982,4 @@ function develitWorker(Worker) {
656
982
  return DevelitWorker;
657
983
  }
658
984
 
659
- export { DatabaseTransaction, RPCResponse, action, 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 };
985
+ export { DatabaseTransaction, Infrastructure, RPCResponse, action, 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 };
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.13.0",
3
+ "version": "5.14.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
7
7
  "type": "module",
8
8
  "scripts": {
9
- "prepack": "unbuild",
10
- "typecheck": "tsc",
9
+ "build": "unbuild",
10
+ "changelogen": "bunx changelogen@latest --bump",
11
11
  "lint": "biome check",
12
12
  "lint:fix": "biome check --fix",
13
- "build": "unbuild",
13
+ "prepack": "unbuild",
14
+ "release": "bun run build && bunx changelogen@latest --release --push && npm publish --access public",
14
15
  "test": "vitest",
15
16
  "test:unit": "vitest test/unit",
16
- "changelogen": "bunx changelogen@latest --bump",
17
- "release": "bun run build && bunx changelogen@latest --release --push && npm publish --access public"
17
+ "typecheck": "tsc"
18
18
  },
19
19
  "exports": {
20
20
  ".": {
@@ -26,18 +26,25 @@
26
26
  },
27
27
  "main": "./dist/index.cjs",
28
28
  "types": "./dist/index.d.ts",
29
- "files": ["dist"],
29
+ "files": [
30
+ "dist"
31
+ ],
30
32
  "dependencies": {
31
- "@cloudflare/workers-types": "^4.20250823.0",
33
+ "@cloudflare/workers-types": "^4.20250906.0",
32
34
  "comment-json": "^4.2.5",
33
35
  "consola": "^3.4.2",
34
36
  "drizzle-kit": "^0.31.4",
35
- "drizzle-orm": "^0.44.4",
37
+ "drizzle-orm": "^0.44.5",
36
38
  "h3": "^1.15.4",
37
39
  "http-status-codes": "2.3.0",
38
40
  "superjson": "^2.2.2"
39
41
  },
40
42
  "peerDependencies": {
41
- "zod": "^4.1.1"
43
+ "sst": "^3.17.12",
44
+ "zod": "^4.1.5"
45
+ },
46
+ "devDependencies": {
47
+ "@cloudflare/workers-types": "4.20250909.0",
48
+ "@pulumi/cloudflare": "^6.8.0"
42
49
  }
43
50
  }