@geekmidas/cloud 0.0.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/README.md ADDED
@@ -0,0 +1 @@
1
+ # @geekmidas/cloud
package/dist/index.cjs ADDED
File without changes
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.mjs ADDED
File without changes
@@ -0,0 +1,109 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const lodash_snakecase = __toESM(require("lodash.snakecase"));
25
+ const os = __toESM(require("os"));
26
+
27
+ //#region src/utils/index.ts
28
+ function getLocalIpAddress() {
29
+ const networkInterfaces = os.default.networkInterfaces();
30
+ for (const interfaceName in networkInterfaces) {
31
+ const addresses = networkInterfaces[interfaceName] || [];
32
+ for (const addressInfo of addresses) if (addressInfo.family === "IPv4" && !addressInfo.internal) return addressInfo.address;
33
+ }
34
+ return null;
35
+ }
36
+ function environmentCase(name) {
37
+ return (0, lodash_snakecase.default)(name).toUpperCase().replace(/_\d+/g, (r) => {
38
+ return r.replace("_", "");
39
+ });
40
+ }
41
+ let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
42
+ ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
43
+ ResourceType$1["Postgres"] = "sst.aws.Postgres";
44
+ ResourceType$1["Function"] = "sst.aws.Function";
45
+ ResourceType$1["Bucket"] = "sst.aws.Bucket";
46
+ ResourceType$1["Vpc"] = "sst.aws.Vpc";
47
+ ResourceType$1["Secret"] = "sst.sst.Secret";
48
+ ResourceType$1["SSTSecret"] = "sst:sst:Secret";
49
+ ResourceType$1["SSTFunction"] = "sst:sst:Function";
50
+ ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
51
+ ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
52
+ ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
53
+ ResourceType$1["SnsTopic"] = "sst:aws:SnsTopic";
54
+ return ResourceType$1;
55
+ }({});
56
+ const secret = (name, value) => ({ [environmentCase(name)]: value.value });
57
+ const postgres = (key, value) => {
58
+ const prefix = `${environmentCase(key)}`;
59
+ return {
60
+ [`${prefix}_NAME`]: value.database,
61
+ [`${prefix}_HOST`]: value.host,
62
+ [`${prefix}_PASSWORD`]: value.password,
63
+ [`${prefix}_PORT`]: value.port,
64
+ [`${prefix}_USERNAME`]: value.username
65
+ };
66
+ };
67
+ const bucket = (name, value) => {
68
+ const prefix = `${environmentCase(name)}`;
69
+ return { [`${prefix}_NAME`]: value.name };
70
+ };
71
+ const topic = (name, value) => {
72
+ const prefix = `${environmentCase(name)}`;
73
+ const key = `${prefix}_ARN`;
74
+ return { [key]: value.arn };
75
+ };
76
+ const noop = (name, value) => ({});
77
+ const processors = {
78
+ [ResourceType.ApiGatewayV2]: noop,
79
+ [ResourceType.Function]: noop,
80
+ [ResourceType.Vpc]: noop,
81
+ [ResourceType.Secret]: secret,
82
+ [ResourceType.Postgres]: postgres,
83
+ [ResourceType.Bucket]: bucket,
84
+ [ResourceType.SSTSecret]: secret,
85
+ [ResourceType.SSTBucket]: bucket,
86
+ [ResourceType.SSTFunction]: noop,
87
+ [ResourceType.SSTPostgres]: postgres,
88
+ [ResourceType.SSTApiGatewayV2]: noop,
89
+ [ResourceType.SnsTopic]: topic
90
+ };
91
+ function buildResourceEnv(record) {
92
+ const env = {};
93
+ for (const [k, value] of Object.entries(record)) {
94
+ if (typeof value === "string") {
95
+ env[environmentCase(k)] = value;
96
+ continue;
97
+ }
98
+ const processor = processors[value.type];
99
+ if (processor) Object.assign(env, processor(k, value));
100
+ else console.warn(`No processor found for resource type: `, { value });
101
+ }
102
+ return env;
103
+ }
104
+
105
+ //#endregion
106
+ exports.ResourceType = ResourceType;
107
+ exports.buildResourceEnv = buildResourceEnv;
108
+ exports.environmentCase = environmentCase;
109
+ exports.getLocalIpAddress = getLocalIpAddress;
@@ -0,0 +1,54 @@
1
+ //#region src/utils/index.d.ts
2
+ declare function getLocalIpAddress(): string | null;
3
+ declare function environmentCase(name: string): string;
4
+ declare enum ResourceType {
5
+ ApiGatewayV2 = "sst.aws.ApiGatewayV2",
6
+ Postgres = "sst.aws.Postgres",
7
+ Function = "sst.aws.Function",
8
+ Bucket = "sst.aws.Bucket",
9
+ Vpc = "sst.aws.Vpc",
10
+ Secret = "sst.sst.Secret",
11
+ SSTSecret = "sst:sst:Secret",
12
+ SSTFunction = "sst:sst:Function",
13
+ SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
14
+ SSTPostgres = "sst:aws:Postgres",
15
+ SSTBucket = "sst:aws:Bucket",
16
+ SnsTopic = "sst:aws:SnsTopic",
17
+ }
18
+ declare function buildResourceEnv(record: Record<string, Resource | string>): Record<string, string>;
19
+ type ApiGatewayV2 = {
20
+ type: ResourceType.ApiGatewayV2;
21
+ url: string;
22
+ };
23
+ type Postgres = {
24
+ database: string;
25
+ host: string;
26
+ password: string;
27
+ port: number;
28
+ type: ResourceType.Postgres;
29
+ username: string;
30
+ };
31
+ type Function = {
32
+ name: string;
33
+ type: ResourceType.Function;
34
+ };
35
+ type Bucket = {
36
+ name: string;
37
+ type: ResourceType.Bucket;
38
+ };
39
+ type SnsTopic = {
40
+ arn: string;
41
+ type: ResourceType.SnsTopic;
42
+ };
43
+ type Vpc = {
44
+ bastion: string;
45
+ type: ResourceType.Vpc;
46
+ };
47
+ type Secret = {
48
+ type: ResourceType.Secret;
49
+ value: string;
50
+ };
51
+ type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
52
+ type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
53
+ //#endregion
54
+ export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, SnsTopic, Vpc, buildResourceEnv, environmentCase, getLocalIpAddress };
@@ -0,0 +1,54 @@
1
+ //#region src/utils/index.d.ts
2
+ declare function getLocalIpAddress(): string | null;
3
+ declare function environmentCase(name: string): string;
4
+ declare enum ResourceType {
5
+ ApiGatewayV2 = "sst.aws.ApiGatewayV2",
6
+ Postgres = "sst.aws.Postgres",
7
+ Function = "sst.aws.Function",
8
+ Bucket = "sst.aws.Bucket",
9
+ Vpc = "sst.aws.Vpc",
10
+ Secret = "sst.sst.Secret",
11
+ SSTSecret = "sst:sst:Secret",
12
+ SSTFunction = "sst:sst:Function",
13
+ SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
14
+ SSTPostgres = "sst:aws:Postgres",
15
+ SSTBucket = "sst:aws:Bucket",
16
+ SnsTopic = "sst:aws:SnsTopic",
17
+ }
18
+ declare function buildResourceEnv(record: Record<string, Resource | string>): Record<string, string>;
19
+ type ApiGatewayV2 = {
20
+ type: ResourceType.ApiGatewayV2;
21
+ url: string;
22
+ };
23
+ type Postgres = {
24
+ database: string;
25
+ host: string;
26
+ password: string;
27
+ port: number;
28
+ type: ResourceType.Postgres;
29
+ username: string;
30
+ };
31
+ type Function = {
32
+ name: string;
33
+ type: ResourceType.Function;
34
+ };
35
+ type Bucket = {
36
+ name: string;
37
+ type: ResourceType.Bucket;
38
+ };
39
+ type SnsTopic = {
40
+ arn: string;
41
+ type: ResourceType.SnsTopic;
42
+ };
43
+ type Vpc = {
44
+ bastion: string;
45
+ type: ResourceType.Vpc;
46
+ };
47
+ type Secret = {
48
+ type: ResourceType.Secret;
49
+ value: string;
50
+ };
51
+ type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
52
+ type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
53
+ //#endregion
54
+ export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, SnsTopic, Vpc, buildResourceEnv, environmentCase, getLocalIpAddress };
@@ -0,0 +1,83 @@
1
+ import snakecase from "lodash.snakecase";
2
+ import os from "os";
3
+
4
+ //#region src/utils/index.ts
5
+ function getLocalIpAddress() {
6
+ const networkInterfaces = os.networkInterfaces();
7
+ for (const interfaceName in networkInterfaces) {
8
+ const addresses = networkInterfaces[interfaceName] || [];
9
+ for (const addressInfo of addresses) if (addressInfo.family === "IPv4" && !addressInfo.internal) return addressInfo.address;
10
+ }
11
+ return null;
12
+ }
13
+ function environmentCase(name) {
14
+ return snakecase(name).toUpperCase().replace(/_\d+/g, (r) => {
15
+ return r.replace("_", "");
16
+ });
17
+ }
18
+ let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
19
+ ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
20
+ ResourceType$1["Postgres"] = "sst.aws.Postgres";
21
+ ResourceType$1["Function"] = "sst.aws.Function";
22
+ ResourceType$1["Bucket"] = "sst.aws.Bucket";
23
+ ResourceType$1["Vpc"] = "sst.aws.Vpc";
24
+ ResourceType$1["Secret"] = "sst.sst.Secret";
25
+ ResourceType$1["SSTSecret"] = "sst:sst:Secret";
26
+ ResourceType$1["SSTFunction"] = "sst:sst:Function";
27
+ ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
28
+ ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
29
+ ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
30
+ ResourceType$1["SnsTopic"] = "sst:aws:SnsTopic";
31
+ return ResourceType$1;
32
+ }({});
33
+ const secret = (name, value) => ({ [environmentCase(name)]: value.value });
34
+ const postgres = (key, value) => {
35
+ const prefix = `${environmentCase(key)}`;
36
+ return {
37
+ [`${prefix}_NAME`]: value.database,
38
+ [`${prefix}_HOST`]: value.host,
39
+ [`${prefix}_PASSWORD`]: value.password,
40
+ [`${prefix}_PORT`]: value.port,
41
+ [`${prefix}_USERNAME`]: value.username
42
+ };
43
+ };
44
+ const bucket = (name, value) => {
45
+ const prefix = `${environmentCase(name)}`;
46
+ return { [`${prefix}_NAME`]: value.name };
47
+ };
48
+ const topic = (name, value) => {
49
+ const prefix = `${environmentCase(name)}`;
50
+ const key = `${prefix}_ARN`;
51
+ return { [key]: value.arn };
52
+ };
53
+ const noop = (name, value) => ({});
54
+ const processors = {
55
+ [ResourceType.ApiGatewayV2]: noop,
56
+ [ResourceType.Function]: noop,
57
+ [ResourceType.Vpc]: noop,
58
+ [ResourceType.Secret]: secret,
59
+ [ResourceType.Postgres]: postgres,
60
+ [ResourceType.Bucket]: bucket,
61
+ [ResourceType.SSTSecret]: secret,
62
+ [ResourceType.SSTBucket]: bucket,
63
+ [ResourceType.SSTFunction]: noop,
64
+ [ResourceType.SSTPostgres]: postgres,
65
+ [ResourceType.SSTApiGatewayV2]: noop,
66
+ [ResourceType.SnsTopic]: topic
67
+ };
68
+ function buildResourceEnv(record) {
69
+ const env = {};
70
+ for (const [k, value] of Object.entries(record)) {
71
+ if (typeof value === "string") {
72
+ env[environmentCase(k)] = value;
73
+ continue;
74
+ }
75
+ const processor = processors[value.type];
76
+ if (processor) Object.assign(env, processor(k, value));
77
+ else console.warn(`No processor found for resource type: `, { value });
78
+ }
79
+ return env;
80
+ }
81
+
82
+ //#endregion
83
+ export { ResourceType, buildResourceEnv, environmentCase, getLocalIpAddress };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@geekmidas/cloud",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.mjs",
9
+ "require": "./dist/index.cjs"
10
+ },
11
+ "./utils": {
12
+ "types": "./dist/utils/index.d.ts",
13
+ "import": "./dist/utils/index.mjs",
14
+ "require": "./dist/utils/index.cjs"
15
+ }
16
+ },
17
+ "publishConfig": {
18
+ "registry": "https://registry.npmjs.org/",
19
+ "access": "public"
20
+ },
21
+ "dependencies": {
22
+ "lodash.snakecase": "~4.1.1",
23
+ "@geekmidas/api": "0.0.52"
24
+ },
25
+ "devDependencies": {
26
+ "@types/lodash.get": "~4.4.9",
27
+ "@types/lodash.set": "~4.3.9",
28
+ "@types/lodash.snakecase": "~4.1.9"
29
+ }
30
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,160 @@
1
+ import snakecase from 'lodash.snakecase';
2
+
3
+ import os from 'os';
4
+
5
+ export function getLocalIpAddress() {
6
+ const networkInterfaces = os.networkInterfaces();
7
+ for (const interfaceName in networkInterfaces) {
8
+ const addresses = networkInterfaces[interfaceName] || [];
9
+ for (const addressInfo of addresses) {
10
+ // Look for an IPv4 address that is not internal (loopback)
11
+ if (addressInfo.family === 'IPv4' && !addressInfo.internal) {
12
+ return addressInfo.address;
13
+ }
14
+ }
15
+ }
16
+ return null; // No suitable IP address found
17
+ }
18
+
19
+ export function environmentCase(name: string) {
20
+ return snakecase(name)
21
+ .toUpperCase()
22
+ .replace(/_\d+/g, (r) => {
23
+ return r.replace('_', '');
24
+ });
25
+ }
26
+ export enum ResourceType {
27
+ ApiGatewayV2 = 'sst.aws.ApiGatewayV2',
28
+ Postgres = 'sst.aws.Postgres',
29
+ Function = 'sst.aws.Function',
30
+ Bucket = 'sst.aws.Bucket',
31
+ Vpc = 'sst.aws.Vpc',
32
+ Secret = 'sst.sst.Secret',
33
+ SSTSecret = 'sst:sst:Secret',
34
+ SSTFunction = 'sst:sst:Function',
35
+ SSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',
36
+ SSTPostgres = 'sst:aws:Postgres',
37
+ SSTBucket = 'sst:aws:Bucket',
38
+ SnsTopic = 'sst:aws:SnsTopic',
39
+ }
40
+
41
+ const secret = (name: string, value: Secret) => ({
42
+ [environmentCase(name)]: value.value,
43
+ });
44
+ const postgres = (key: string, value: Postgres) => {
45
+ const prefix = `${environmentCase(key)}`;
46
+ return {
47
+ [`${prefix}_NAME`]: value.database,
48
+ [`${prefix}_HOST`]: value.host,
49
+ [`${prefix}_PASSWORD`]: value.password,
50
+ [`${prefix}_PORT`]: value.port,
51
+ [`${prefix}_USERNAME`]: value.username,
52
+ };
53
+ };
54
+
55
+ const bucket = (name: string, value: Bucket) => {
56
+ const prefix = `${environmentCase(name)}`;
57
+ return {
58
+ [`${prefix}_NAME`]: value.name,
59
+ };
60
+ };
61
+
62
+ const topic = (name: string, value: SnsTopic) => {
63
+ const prefix = `${environmentCase(name)}`;
64
+ const key = `${prefix}_ARN`;
65
+
66
+ return {
67
+ [key]: value.arn,
68
+ };
69
+ };
70
+
71
+ const noop = (name: string, value: any) => ({});
72
+
73
+ const processors: Record<ResourceType, ResourceProcessor<any>> = {
74
+ [ResourceType.ApiGatewayV2]: noop,
75
+ [ResourceType.Function]: noop,
76
+ [ResourceType.Vpc]: noop,
77
+ [ResourceType.Secret]: secret,
78
+ [ResourceType.Postgres]: postgres,
79
+ [ResourceType.Bucket]: bucket,
80
+
81
+ [ResourceType.SSTSecret]: secret,
82
+ [ResourceType.SSTBucket]: bucket,
83
+ [ResourceType.SSTFunction]: noop,
84
+ [ResourceType.SSTPostgres]: postgres,
85
+ [ResourceType.SSTApiGatewayV2]: noop,
86
+ [ResourceType.SnsTopic]: topic,
87
+ };
88
+
89
+ export function buildResourceEnv(
90
+ record: Record<string, Resource | string>,
91
+ ): Record<string, string> {
92
+ const env: Record<string, string> = {};
93
+ for (const [k, value] of Object.entries(record)) {
94
+ if (typeof value === 'string') {
95
+ env[environmentCase(k)] = value;
96
+ continue;
97
+ }
98
+
99
+ const processor = processors[value.type];
100
+ if (processor) {
101
+ Object.assign(env, processor(k, value));
102
+ } else {
103
+ console.warn(`No processor found for resource type: `, { value });
104
+ }
105
+ }
106
+
107
+ return env;
108
+ }
109
+
110
+ export type ApiGatewayV2 = {
111
+ type: ResourceType.ApiGatewayV2;
112
+ url: string;
113
+ };
114
+
115
+ export type Postgres = {
116
+ database: string;
117
+ host: string;
118
+ password: string;
119
+ port: number;
120
+ type: ResourceType.Postgres;
121
+ username: string;
122
+ };
123
+
124
+ export type Function = {
125
+ name: string;
126
+ type: ResourceType.Function;
127
+ };
128
+
129
+ export type Bucket = {
130
+ name: string;
131
+ type: ResourceType.Bucket;
132
+ };
133
+
134
+ export type SnsTopic = {
135
+ arn: string;
136
+ type: ResourceType.SnsTopic;
137
+ };
138
+
139
+ export type Vpc = {
140
+ bastion: string;
141
+ type: ResourceType.Vpc;
142
+ };
143
+
144
+ export type Secret = {
145
+ type: ResourceType.Secret;
146
+ value: string;
147
+ };
148
+
149
+ export type Resource =
150
+ | ApiGatewayV2
151
+ | Postgres
152
+ | Function
153
+ | Bucket
154
+ | Vpc
155
+ | Secret;
156
+
157
+ export type ResourceProcessor<K extends Resource> = (
158
+ name: string,
159
+ value: K,
160
+ ) => Record<string, string | number>;
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from 'tsdown';
2
+
3
+ export default defineConfig({});