@develit-io/backend-sdk 5.20.0 → 5.21.1
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 +65 -48
- package/dist/index.d.cts +78 -94
- package/dist/index.d.mts +78 -94
- package/dist/index.d.ts +78 -94
- package/dist/index.mjs +65 -49
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,9 @@ 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
5
|
import { toSnakeCase } from '@std/text';
|
|
6
|
-
import '
|
|
6
|
+
import { KVNamespace, D1Database, Queue, R2Bucket } from 'alchemy/cloudflare';
|
|
7
7
|
import * as z from 'zod/v4/core';
|
|
8
|
+
import 'http-status-codes';
|
|
8
9
|
import { createError } from 'h3';
|
|
9
10
|
import fs from 'node:fs';
|
|
10
11
|
import crypto$1 from 'node:crypto';
|
|
@@ -59,12 +60,9 @@ const composeD1Arguments = ({
|
|
|
59
60
|
resourceName
|
|
60
61
|
}) => {
|
|
61
62
|
return {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
primaryLocationHint: "weur"
|
|
66
|
-
}
|
|
67
|
-
}
|
|
63
|
+
name: resourceName,
|
|
64
|
+
primaryLocationHint: "weur"
|
|
65
|
+
// TODO: It's possible that it will take care of migrations as well
|
|
68
66
|
};
|
|
69
67
|
};
|
|
70
68
|
|
|
@@ -72,11 +70,7 @@ const composeKvArguments = ({
|
|
|
72
70
|
resourceName
|
|
73
71
|
}) => {
|
|
74
72
|
return {
|
|
75
|
-
|
|
76
|
-
namespace: {
|
|
77
|
-
title: resourceName
|
|
78
|
-
}
|
|
79
|
-
}
|
|
73
|
+
title: resourceName
|
|
80
74
|
};
|
|
81
75
|
};
|
|
82
76
|
|
|
@@ -86,14 +80,10 @@ const composeQueueArguments = ({
|
|
|
86
80
|
messageRetentionPeriod = 259200
|
|
87
81
|
}) => {
|
|
88
82
|
return {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
deliveryDelay,
|
|
94
|
-
messageRetentionPeriod
|
|
95
|
-
}
|
|
96
|
-
}
|
|
83
|
+
name: resourceName,
|
|
84
|
+
settings: {
|
|
85
|
+
deliveryDelay,
|
|
86
|
+
messageRetentionPeriod
|
|
97
87
|
}
|
|
98
88
|
};
|
|
99
89
|
};
|
|
@@ -103,14 +93,10 @@ const composeR2Arguments = ({
|
|
|
103
93
|
storageClass = "Standard"
|
|
104
94
|
}) => {
|
|
105
95
|
return {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
location: "weur",
|
|
111
|
-
storageClass
|
|
112
|
-
}
|
|
113
|
-
}
|
|
96
|
+
name: resourceName,
|
|
97
|
+
jurisdiction: "eu",
|
|
98
|
+
locationHint: "weur",
|
|
99
|
+
storageClass
|
|
114
100
|
};
|
|
115
101
|
};
|
|
116
102
|
|
|
@@ -133,23 +119,20 @@ const composeResourceName = ({
|
|
|
133
119
|
class Infrastructure {
|
|
134
120
|
project;
|
|
135
121
|
environment;
|
|
136
|
-
sst;
|
|
137
122
|
constructor({
|
|
138
123
|
project,
|
|
139
|
-
environment
|
|
140
|
-
sst
|
|
124
|
+
environment
|
|
141
125
|
}) {
|
|
142
126
|
this.project = project;
|
|
143
127
|
this.environment = environment;
|
|
144
|
-
this.sst = sst;
|
|
145
128
|
}
|
|
146
129
|
/**
|
|
147
130
|
* Creates an instance of Cloudflare KV.
|
|
148
131
|
*/
|
|
149
|
-
kv(options) {
|
|
150
|
-
const { resourceName
|
|
151
|
-
return
|
|
152
|
-
|
|
132
|
+
async kv(options) {
|
|
133
|
+
const { resourceName } = options;
|
|
134
|
+
return await KVNamespace(
|
|
135
|
+
resourceName,
|
|
153
136
|
composeKvArguments({
|
|
154
137
|
resourceName: composeResourceName({
|
|
155
138
|
project: this.project,
|
|
@@ -162,10 +145,10 @@ class Infrastructure {
|
|
|
162
145
|
/**
|
|
163
146
|
* Creates an instance of Cloudflare D1.
|
|
164
147
|
*/
|
|
165
|
-
d1(options) {
|
|
166
|
-
const { resourceName
|
|
167
|
-
return
|
|
168
|
-
|
|
148
|
+
async d1(options) {
|
|
149
|
+
const { resourceName } = options;
|
|
150
|
+
return await D1Database(
|
|
151
|
+
resourceName,
|
|
169
152
|
composeD1Arguments({
|
|
170
153
|
resourceName: composeResourceName({
|
|
171
154
|
project: this.project,
|
|
@@ -178,10 +161,10 @@ class Infrastructure {
|
|
|
178
161
|
/**
|
|
179
162
|
* Creates an instance of Cloudflare Queue.
|
|
180
163
|
*/
|
|
181
|
-
queue(options) {
|
|
182
|
-
const { resourceName,
|
|
183
|
-
return
|
|
184
|
-
|
|
164
|
+
async queue(options) {
|
|
165
|
+
const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
|
|
166
|
+
return await Queue(
|
|
167
|
+
resourceName,
|
|
185
168
|
composeQueueArguments({
|
|
186
169
|
resourceName: composeResourceName({
|
|
187
170
|
project: this.project,
|
|
@@ -196,10 +179,10 @@ class Infrastructure {
|
|
|
196
179
|
/**
|
|
197
180
|
* Creates an instance of Cloudflare R2.
|
|
198
181
|
*/
|
|
199
|
-
r2(options) {
|
|
200
|
-
const { resourceName,
|
|
201
|
-
return
|
|
202
|
-
|
|
182
|
+
async r2(options) {
|
|
183
|
+
const { resourceName, storageClass } = options;
|
|
184
|
+
return await R2Bucket(
|
|
185
|
+
resourceName,
|
|
203
186
|
composeR2Arguments({
|
|
204
187
|
resourceName: composeResourceName({
|
|
205
188
|
project: this.project,
|
|
@@ -663,6 +646,39 @@ const defineCommand = (handler) => {
|
|
|
663
646
|
}));
|
|
664
647
|
};
|
|
665
648
|
|
|
649
|
+
async function useFetch(url, { parseAs = "json", ...options } = {}) {
|
|
650
|
+
const [response, fetchError] = await useResult(fetch(url, options));
|
|
651
|
+
if (fetchError || !response) {
|
|
652
|
+
return [null, createInternalError(fetchError, { code: "NETWORK_ERROR" })];
|
|
653
|
+
}
|
|
654
|
+
const parsers = {
|
|
655
|
+
json: () => response.json(),
|
|
656
|
+
text: () => response.text(),
|
|
657
|
+
blob: () => response.blob()
|
|
658
|
+
};
|
|
659
|
+
const [body, parseError] = await useResult(parsers[parseAs]());
|
|
660
|
+
if (!response.ok) {
|
|
661
|
+
return [
|
|
662
|
+
null,
|
|
663
|
+
createInternalError(parseError, {
|
|
664
|
+
message: body?.message ?? response.statusText,
|
|
665
|
+
code: "HTTP_ERROR",
|
|
666
|
+
status: response.status
|
|
667
|
+
})
|
|
668
|
+
];
|
|
669
|
+
}
|
|
670
|
+
if (parseError) {
|
|
671
|
+
return [
|
|
672
|
+
null,
|
|
673
|
+
createInternalError(parseError, {
|
|
674
|
+
code: "PARSE_ERROR",
|
|
675
|
+
status: response.status
|
|
676
|
+
})
|
|
677
|
+
];
|
|
678
|
+
}
|
|
679
|
+
return [body, null];
|
|
680
|
+
}
|
|
681
|
+
|
|
666
682
|
const getPgLocalConnectionString = (id) => `postgres://db_user:db_password@127.0.0.1:${derivePortFromId(id)}/db`;
|
|
667
683
|
const getPgDatabaseIdFromWrangler = () => {
|
|
668
684
|
try {
|
|
@@ -852,4 +868,4 @@ function develitWorker(Worker) {
|
|
|
852
868
|
return DevelitWorker;
|
|
853
869
|
}
|
|
854
870
|
|
|
855
|
-
export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, 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, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useResult, useResultSync, uuidv4, validateEnvironment };
|
|
871
|
+
export { DatabaseTransaction, ENVIRONMENT, Infrastructure, RPCResponse, action, bankAccount, bankAccountBankCodeEnum, bankAccountCountryCodeEnum, bankAccountCurrencyEnum, 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, paginationQuerySchema, paginationSchema, service, swiftZodSchema, useFetch, useResult, useResultSync, uuidv4, validateEnvironment };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@develit-io/backend-sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.21.1",
|
|
4
4
|
"description": "Develit Backend SDK",
|
|
5
5
|
"author": "Develit.io",
|
|
6
6
|
"license": "ISC",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@cloudflare/workers-types": "4.20250923.0",
|
|
37
|
-
"@pulumi/cloudflare": "^6.9.1",
|
|
38
37
|
"@std/path": "npm:@jsr/std__path",
|
|
39
38
|
"@std/text": "npm:@jsr/std__text",
|
|
39
|
+
"alchemy": "^0.69.0",
|
|
40
40
|
"comment-json": "^4.2.5",
|
|
41
41
|
"drizzle-kit": "^0.31.4",
|
|
42
42
|
"drizzle-orm": "^0.44.5",
|