@develit-io/backend-sdk 5.21.4 → 5.22.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.
@@ -0,0 +1,148 @@
1
+ import { P as Project, E as Environment } from '../shared/backend-sdk._l2mbzzF.js';
2
+ import { KVNamespace, D1Database, Queue, R2Bucket, Bindings, Worker } from 'alchemy/cloudflare';
3
+
4
+ type Resource = 'kv' | 'd1' | 'queue' | 'r2' | 'worker' | 'service' | 'orchestrator';
5
+
6
+ declare class Infrastructure {
7
+ private project;
8
+ private environment;
9
+ constructor({ project, environment, }: {
10
+ project: Project;
11
+ environment: Environment;
12
+ });
13
+ /**
14
+ * Creates an instance of Cloudflare KV.
15
+ */
16
+ kv(options: {
17
+ /**
18
+ * Name of the KV. Do not include the 'kv' prefix.
19
+ */
20
+ resourceName: string;
21
+ }): Promise<KVNamespace>;
22
+ /**
23
+ * Creates an instance of Cloudflare D1.
24
+ */
25
+ d1(options: {
26
+ /**
27
+ * Name of the D1. Do not include the 'd1' prefix.
28
+ */
29
+ resourceName: string;
30
+ }): Promise<D1Database>;
31
+ /**
32
+ * Creates an instance of Cloudflare Queue.
33
+ */
34
+ queue(options: {
35
+ /**
36
+ * Name of the Queue. Do not include the 'queue' prefix.
37
+ */
38
+ resourceName: string;
39
+ /**
40
+ * The number of seconds to delay delivery of messages to the queue.
41
+ */
42
+ deliveryDelay?: number;
43
+ /**
44
+ * The number of seconds a message will remain in the queue before being deleted.
45
+ */
46
+ messageRetentionPeriod?: number;
47
+ }): Promise<Queue<unknown>>;
48
+ /**
49
+ * Creates an instance of Cloudflare R2.
50
+ */
51
+ r2(options: {
52
+ /**
53
+ * Name of the R2. Do not include the 'r2' prefix.
54
+ */
55
+ resourceName: string;
56
+ /**
57
+ * The storage class for the R2 bucket.
58
+ */
59
+ storageClass?: 'Standard' | 'InfrequentAccess';
60
+ }): Promise<R2Bucket>;
61
+ /**
62
+ * Creates an instance of Cloudflare Worker.
63
+ */
64
+ worker(options: {
65
+ /**
66
+ * Name of the Worker. Do not include the 'worker' prefix.
67
+ */
68
+ resourceName: string;
69
+ /**
70
+ * Entrypoint file of the Worker.
71
+ */
72
+ entrypoint: string;
73
+ /**
74
+ * Bindings of the Worker.
75
+ */
76
+ bindings: Bindings;
77
+ /**
78
+ * Event sources for the service to consume.
79
+ */
80
+ eventSources?: Queue[];
81
+ }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
82
+ /**
83
+ * Creates an instance of Cloudflare Worker as a service.
84
+ */
85
+ service(options: {
86
+ /**
87
+ * Name of the service. Do not include the 'service' prefix.
88
+ */
89
+ resourceName: string;
90
+ /**
91
+ * Bindings of the Worker.
92
+ */
93
+ bindings: Bindings;
94
+ /**
95
+ * Event sources for the service to consume.
96
+ */
97
+ eventSources?: Queue[];
98
+ }): Promise<Worker<Bindings, Rpc.WorkerEntrypointBranded>>;
99
+ }
100
+
101
+ declare const composeD1Arguments: ({ resourceName, }: {
102
+ resourceName: string;
103
+ }) => {
104
+ name: string;
105
+ primaryLocationHint: "weur";
106
+ };
107
+
108
+ declare const composeKvArguments: ({ resourceName, }: {
109
+ resourceName: string;
110
+ }) => {
111
+ title: string;
112
+ };
113
+
114
+ declare const composeQueueArguments: ({ resourceName, deliveryDelay, messageRetentionPeriod, }: {
115
+ resourceName: string;
116
+ deliveryDelay?: number;
117
+ messageRetentionPeriod?: number;
118
+ }) => {
119
+ name: string;
120
+ settings: {
121
+ deliveryDelay: number;
122
+ messageRetentionPeriod: number;
123
+ };
124
+ };
125
+
126
+ declare const composeR2Arguments: ({ resourceName, storageClass, }: {
127
+ resourceName: string;
128
+ storageClass?: "Standard" | "InfrequentAccess";
129
+ }) => {
130
+ name: string;
131
+ jurisdiction: "eu";
132
+ locationHint: string;
133
+ storageClass: "Standard" | "InfrequentAccess";
134
+ };
135
+
136
+ declare const composeIdentifierName: ({ resource, resourceName, }: {
137
+ resource: Resource;
138
+ resourceName: string;
139
+ }) => string;
140
+ declare const composeResourceName: ({ project, environment, resourceName, }: {
141
+ project: Project;
142
+ environment: Environment;
143
+ resourceName: string;
144
+ }) => string;
145
+
146
+ declare const validateEnvironment: (environment: string) => Environment;
147
+
148
+ export { Infrastructure, composeD1Arguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName, validateEnvironment };
@@ -0,0 +1,184 @@
1
+ import { D as D1_LOCATION_HINT, Q as QUEUE_MESSAGE_RETENTION_PERIOD, a as QUEUE_DELIVERY_DELAY, R as R2_STORAGE_CLASS, b as R2_LOCATION_HINT, c as R2_JURISDICTION, d as composeWorkerArguments } from '../shared/backend-sdk.CxCzOVpU.mjs';
2
+ import { KVNamespace, D1Database, Queue, R2Bucket, Worker } from 'alchemy/cloudflare';
3
+ import { E as ENVIRONMENT } from '../shared/backend-sdk.DXRpnctc.mjs';
4
+
5
+ const composeD1Arguments = ({
6
+ resourceName
7
+ }) => {
8
+ return {
9
+ name: resourceName,
10
+ primaryLocationHint: D1_LOCATION_HINT
11
+ };
12
+ };
13
+
14
+ const composeKvArguments = ({
15
+ resourceName
16
+ }) => {
17
+ return {
18
+ title: resourceName
19
+ };
20
+ };
21
+
22
+ const composeQueueArguments = ({
23
+ resourceName,
24
+ deliveryDelay = QUEUE_DELIVERY_DELAY,
25
+ messageRetentionPeriod = QUEUE_MESSAGE_RETENTION_PERIOD
26
+ }) => {
27
+ return {
28
+ name: resourceName,
29
+ settings: {
30
+ deliveryDelay,
31
+ messageRetentionPeriod
32
+ }
33
+ };
34
+ };
35
+
36
+ const composeR2Arguments = ({
37
+ resourceName,
38
+ storageClass = R2_STORAGE_CLASS
39
+ }) => {
40
+ return {
41
+ name: resourceName,
42
+ jurisdiction: R2_JURISDICTION,
43
+ locationHint: R2_LOCATION_HINT,
44
+ storageClass
45
+ };
46
+ };
47
+
48
+ const composeIdentifierName = ({
49
+ resource,
50
+ resourceName
51
+ }) => {
52
+ return `${resourceName}-${resource}`;
53
+ };
54
+ const composeResourceName = ({
55
+ project,
56
+ environment,
57
+ resourceName
58
+ }) => {
59
+ return `${project}-${resourceName}-${environment}`;
60
+ };
61
+
62
+ class Infrastructure {
63
+ project;
64
+ environment;
65
+ constructor({
66
+ project,
67
+ environment
68
+ }) {
69
+ this.project = project;
70
+ this.environment = environment;
71
+ }
72
+ /**
73
+ * Creates an instance of Cloudflare KV.
74
+ */
75
+ async kv(options) {
76
+ const { resourceName } = options;
77
+ return await KVNamespace(
78
+ composeIdentifierName({ resourceName, resource: "kv" }),
79
+ composeKvArguments({
80
+ resourceName: composeResourceName({
81
+ project: this.project,
82
+ environment: this.environment,
83
+ resourceName
84
+ })
85
+ })
86
+ );
87
+ }
88
+ /**
89
+ * Creates an instance of Cloudflare D1.
90
+ */
91
+ async d1(options) {
92
+ const { resourceName } = options;
93
+ return await D1Database(
94
+ composeIdentifierName({ resourceName, resource: "d1" }),
95
+ composeD1Arguments({
96
+ resourceName: composeResourceName({
97
+ project: this.project,
98
+ environment: this.environment,
99
+ resourceName
100
+ })
101
+ })
102
+ );
103
+ }
104
+ /**
105
+ * Creates an instance of Cloudflare Queue.
106
+ */
107
+ async queue(options) {
108
+ const { resourceName, deliveryDelay, messageRetentionPeriod } = options;
109
+ return await Queue(
110
+ composeIdentifierName({ resourceName, resource: "queue" }),
111
+ composeQueueArguments({
112
+ resourceName: composeResourceName({
113
+ project: this.project,
114
+ environment: this.environment,
115
+ resourceName
116
+ }),
117
+ deliveryDelay,
118
+ messageRetentionPeriod
119
+ })
120
+ );
121
+ }
122
+ /**
123
+ * Creates an instance of Cloudflare R2.
124
+ */
125
+ async r2(options) {
126
+ const { resourceName, storageClass } = options;
127
+ return await R2Bucket(
128
+ composeIdentifierName({ resourceName, resource: "r2" }),
129
+ composeR2Arguments({
130
+ resourceName: composeResourceName({
131
+ project: this.project,
132
+ environment: this.environment,
133
+ resourceName
134
+ }),
135
+ storageClass
136
+ })
137
+ );
138
+ }
139
+ /**
140
+ * Creates an instance of Cloudflare Worker.
141
+ */
142
+ async worker(options) {
143
+ const { resourceName, entrypoint, bindings, eventSources } = options;
144
+ const identifierName = composeIdentifierName({
145
+ resourceName,
146
+ resource: "worker"
147
+ });
148
+ return await Worker(
149
+ identifierName,
150
+ composeWorkerArguments({
151
+ resourceName: composeResourceName({
152
+ project: this.project,
153
+ environment: this.environment,
154
+ resourceName: identifierName
155
+ }),
156
+ entrypoint,
157
+ bindings,
158
+ eventSources
159
+ })
160
+ );
161
+ }
162
+ /**
163
+ * Creates an instance of Cloudflare Worker as a service.
164
+ */
165
+ async service(options) {
166
+ const { resourceName, bindings, eventSources } = options;
167
+ return await this.worker({
168
+ resourceName,
169
+ // TODO: Convert to util
170
+ entrypoint: `./services/${resourceName}/src/index.ts`,
171
+ bindings,
172
+ eventSources
173
+ });
174
+ }
175
+ }
176
+
177
+ const validateEnvironment = (environment) => {
178
+ if (ENVIRONMENT.includes(environment)) {
179
+ return environment;
180
+ }
181
+ return Number(environment);
182
+ };
183
+
184
+ export { Infrastructure, composeD1Arguments, composeIdentifierName, composeKvArguments, composeQueueArguments, composeR2Arguments, composeResourceName, validateEnvironment };
@@ -1,12 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const commentJson = require('comment-json');
4
- const fs = require('node:fs');
5
- const path = require('@std/path');
3
+ const node_index = require('../shared/backend-sdk.CpwGFVDb.cjs');
6
4
 
7
- async function loadWorkerConfig({ path: path$1 }) {
8
- const workerConfigFile = fs.readFileSync(path.join(path$1, "./wrangler.jsonc"), "utf-8");
9
- return commentJson.parse(workerConfigFile);
10
- }
11
5
 
12
- exports.loadWorkerConfig = loadWorkerConfig;
6
+
7
+ exports.composeWorkerArguments = node_index.composeWorkerArguments;
@@ -1,7 +1,21 @@
1
- import * as comment_json from 'comment-json';
1
+ import { Bindings, Queue } from 'alchemy/cloudflare';
2
2
 
3
- declare function loadWorkerConfig({ path }: {
4
- path: string;
5
- }): Promise<comment_json.CommentJSONValue>;
3
+ declare const composeWorkerArguments: ({ resourceName, entrypoint, bindings, eventSources, }: {
4
+ resourceName: string;
5
+ entrypoint: string;
6
+ bindings: Bindings;
7
+ eventSources?: Queue[];
8
+ }) => {
9
+ name: string;
10
+ entrypoint: string;
11
+ compatibilityFlags: string[];
12
+ compatibilityDate: string;
13
+ observability: {
14
+ enabled: true;
15
+ };
16
+ url: false;
17
+ eventSources: Queue[];
18
+ bindings: Bindings;
19
+ };
6
20
 
7
- export { loadWorkerConfig };
21
+ export { composeWorkerArguments };
@@ -1,7 +1,21 @@
1
- import * as comment_json from 'comment-json';
1
+ import { Bindings, Queue } from 'alchemy/cloudflare';
2
2
 
3
- declare function loadWorkerConfig({ path }: {
4
- path: string;
5
- }): Promise<comment_json.CommentJSONValue>;
3
+ declare const composeWorkerArguments: ({ resourceName, entrypoint, bindings, eventSources, }: {
4
+ resourceName: string;
5
+ entrypoint: string;
6
+ bindings: Bindings;
7
+ eventSources?: Queue[];
8
+ }) => {
9
+ name: string;
10
+ entrypoint: string;
11
+ compatibilityFlags: string[];
12
+ compatibilityDate: string;
13
+ observability: {
14
+ enabled: true;
15
+ };
16
+ url: false;
17
+ eventSources: Queue[];
18
+ bindings: Bindings;
19
+ };
6
20
 
7
- export { loadWorkerConfig };
21
+ export { composeWorkerArguments };
@@ -1,7 +1,21 @@
1
- import * as comment_json from 'comment-json';
1
+ import { Bindings, Queue } from 'alchemy/cloudflare';
2
2
 
3
- declare function loadWorkerConfig({ path }: {
4
- path: string;
5
- }): Promise<comment_json.CommentJSONValue>;
3
+ declare const composeWorkerArguments: ({ resourceName, entrypoint, bindings, eventSources, }: {
4
+ resourceName: string;
5
+ entrypoint: string;
6
+ bindings: Bindings;
7
+ eventSources?: Queue[];
8
+ }) => {
9
+ name: string;
10
+ entrypoint: string;
11
+ compatibilityFlags: string[];
12
+ compatibilityDate: string;
13
+ observability: {
14
+ enabled: true;
15
+ };
16
+ url: false;
17
+ eventSources: Queue[];
18
+ bindings: Bindings;
19
+ };
6
20
 
7
- export { loadWorkerConfig };
21
+ export { composeWorkerArguments };
@@ -1,10 +1 @@
1
- import { parse } from 'comment-json';
2
- import { readFileSync } from 'node:fs';
3
- import { join } from '@std/path';
4
-
5
- async function loadWorkerConfig({ path }) {
6
- const workerConfigFile = readFileSync(join(path, "./wrangler.jsonc"), "utf-8");
7
- return parse(workerConfigFile);
8
- }
9
-
10
- export { loadWorkerConfig };
1
+ export { d as composeWorkerArguments } from '../shared/backend-sdk.CxCzOVpU.mjs';
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
4
+
5
+ exports.ENVIRONMENT = ENVIRONMENT;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const COMPATIBILITY_DATE = "2025-06-04";
4
+ const COMPATIBILITY_FLAGS = ["nodejs_compat"];
5
+ const QUEUE_DELIVERY_DELAY = 5;
6
+ const QUEUE_MESSAGE_RETENTION_PERIOD = 259200;
7
+ const D1_LOCATION_HINT = "weur";
8
+ const R2_STORAGE_CLASS = "Standard";
9
+ const R2_JURISDICTION = "eu";
10
+ const R2_LOCATION_HINT = "weur";
11
+
12
+ const composeWorkerArguments = ({
13
+ resourceName,
14
+ entrypoint,
15
+ bindings,
16
+ eventSources = []
17
+ }) => {
18
+ return {
19
+ name: resourceName,
20
+ entrypoint,
21
+ compatibilityFlags: COMPATIBILITY_FLAGS,
22
+ compatibilityDate: COMPATIBILITY_DATE,
23
+ observability: {
24
+ enabled: true
25
+ },
26
+ url: false,
27
+ eventSources,
28
+ bindings
29
+ };
30
+ };
31
+
32
+ exports.D1_LOCATION_HINT = D1_LOCATION_HINT;
33
+ exports.QUEUE_DELIVERY_DELAY = QUEUE_DELIVERY_DELAY;
34
+ exports.QUEUE_MESSAGE_RETENTION_PERIOD = QUEUE_MESSAGE_RETENTION_PERIOD;
35
+ exports.R2_JURISDICTION = R2_JURISDICTION;
36
+ exports.R2_LOCATION_HINT = R2_LOCATION_HINT;
37
+ exports.R2_STORAGE_CLASS = R2_STORAGE_CLASS;
38
+ exports.composeWorkerArguments = composeWorkerArguments;
@@ -0,0 +1,30 @@
1
+ const COMPATIBILITY_DATE = "2025-06-04";
2
+ const COMPATIBILITY_FLAGS = ["nodejs_compat"];
3
+ const QUEUE_DELIVERY_DELAY = 5;
4
+ const QUEUE_MESSAGE_RETENTION_PERIOD = 259200;
5
+ const D1_LOCATION_HINT = "weur";
6
+ const R2_STORAGE_CLASS = "Standard";
7
+ const R2_JURISDICTION = "eu";
8
+ const R2_LOCATION_HINT = "weur";
9
+
10
+ const composeWorkerArguments = ({
11
+ resourceName,
12
+ entrypoint,
13
+ bindings,
14
+ eventSources = []
15
+ }) => {
16
+ return {
17
+ name: resourceName,
18
+ entrypoint,
19
+ compatibilityFlags: COMPATIBILITY_FLAGS,
20
+ compatibilityDate: COMPATIBILITY_DATE,
21
+ observability: {
22
+ enabled: true
23
+ },
24
+ url: false,
25
+ eventSources,
26
+ bindings
27
+ };
28
+ };
29
+
30
+ export { D1_LOCATION_HINT as D, QUEUE_MESSAGE_RETENTION_PERIOD as Q, R2_STORAGE_CLASS as R, QUEUE_DELIVERY_DELAY as a, R2_LOCATION_HINT as b, R2_JURISDICTION as c, composeWorkerArguments as d };
@@ -0,0 +1,3 @@
1
+ const ENVIRONMENT = ["dev", "test", "staging", "production"];
2
+
3
+ export { ENVIRONMENT as E };
@@ -0,0 +1,5 @@
1
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
2
+
3
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'dbu-txs';
4
+
5
+ export type { Environment as E, Project as P };
@@ -0,0 +1,5 @@
1
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
2
+
3
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'dbu-txs';
4
+
5
+ export type { Environment as E, Project as P };
@@ -0,0 +1,5 @@
1
+ type Environment = number | 'dev' | 'test' | 'staging' | 'production';
2
+
3
+ type Project = 'creditio' | 'fp' | 'mdm' | 'moneio' | 'dbu-txs';
4
+
5
+ export type { Environment as E, Project as P };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@develit-io/backend-sdk",
3
- "version": "5.21.4",
3
+ "version": "5.22.0",
4
4
  "description": "Develit Backend SDK",
5
5
  "author": "Develit.io",
6
6
  "license": "ISC",
@@ -22,6 +22,11 @@
22
22
  "import": "./dist/index.mjs",
23
23
  "require": "./dist/index.cjs"
24
24
  },
25
+ "./infrastructure": {
26
+ "types": "./dist/infrastructure/index.d.ts",
27
+ "import": "./dist/infrastructure/index.mjs",
28
+ "require": "./dist/infrastructure/index.cjs"
29
+ },
25
30
  "./node": {
26
31
  "types": "./dist/node/index.d.ts",
27
32
  "import": "./dist/node/index.mjs",