@geekmidas/cloud 10.0.0-alpha.99 → 10.0.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/README.md +6 -14
- package/dist/index-ByEJy40r.d.cts +56 -0
- package/dist/index-ByEJy40r.d.cts.map +1 -0
- package/dist/index-DZ0QrJQr.d.mts +56 -0
- package/dist/index-DZ0QrJQr.d.mts.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +3 -2
- package/dist/utils/index.cjs +5 -106
- package/dist/utils/index.d.cts +2 -62
- package/dist/utils/index.d.mts +2 -62
- package/dist/utils/index.mjs +2 -78
- package/dist/utils-BdKG20_m.mjs +83 -0
- package/dist/utils-BdKG20_m.mjs.map +1 -0
- package/dist/utils-CtMjuIMR.cjs +129 -0
- package/dist/utils-CtMjuIMR.cjs.map +1 -0
- package/package.json +9 -47
- package/src/sst/{aws/Api.ts → Api.ts} +47 -19
- package/src/sst/{aws/Cron.ts → Cron.ts} +46 -6
- package/src/sst/{aws/Function.ts → Function.ts} +41 -12
- package/src/sst/Queue.ts +46 -0
- package/src/sst/{aws/Storage.ts → Storage.ts} +3 -3
- package/src/sst/Topic.ts +37 -0
- package/src/sst/__tests__/LinkedEnvironment.spec.ts +1 -4
- package/src/sst/__type-tests__/authorizers.type-test.ts +2 -2
- package/src/sst/__type-tests__/manifest.type-test.ts +77 -0
- package/src/sst/__type-tests__/messaging.type-test.ts +3 -3
- package/src/sst/__type-tests__/storage.type-test.ts +2 -2
- package/src/sst/index.ts +7 -67
- package/src/sst/naming.ts +16 -37
- package/src/sst/tsconfig.json +2 -2
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.d.cts.map +0 -1
- package/dist/utils/index.d.mts.map +0 -1
- package/dist/utils/index.mjs.map +0 -1
- package/src/dokploy/Application.ts +0 -306
- package/src/dokploy/__tests__/Application.provider.spec.ts +0 -206
- package/src/dokploy/__tests__/Application.spec.ts +0 -69
- package/src/dokploy/index.ts +0 -18
- package/src/sst/__tests__/api.spec.ts +0 -185
- package/src/sst/__tests__/backends.spec.ts +0 -249
- package/src/sst/__tests__/bootstrap.spec.ts +0 -140
- package/src/sst/__tests__/database.spec.ts +0 -119
- package/src/sst/__tests__/encryption.spec.ts +0 -90
- package/src/sst/__tests__/fromManifest.integration.spec.ts +0 -427
- package/src/sst/__tests__/fromManifest.spec.ts +0 -567
- package/src/sst/__tests__/function.spec.ts +0 -121
- package/src/sst/__tests__/links.spec.ts +0 -209
- package/src/sst/__tests__/provides.spec.ts +0 -107
- package/src/sst/__tests__/ses.spec.ts +0 -93
- package/src/sst/__tests__/surfaces.spec.ts +0 -149
- package/src/sst/__type-tests__/overrides.type-test.ts +0 -152
- package/src/sst/aws/Cache.ts +0 -259
- package/src/sst/aws/Credential.ts +0 -61
- package/src/sst/aws/Database.ts +0 -204
- package/src/sst/aws/DatabaseBootstrap.ts +0 -312
- package/src/sst/aws/DerivedDatabase.ts +0 -117
- package/src/sst/aws/Email.ts +0 -181
- package/src/sst/aws/Encryption.ts +0 -91
- package/src/sst/aws/ExternalApi.ts +0 -58
- package/src/sst/aws/FileServer.ts +0 -82
- package/src/sst/aws/ObjectStorage.ts +0 -76
- package/src/sst/aws/Queue.ts +0 -149
- package/src/sst/aws/RestApiSurface.ts +0 -114
- package/src/sst/aws/Secret.ts +0 -76
- package/src/sst/aws/StaticSite.ts +0 -92
- package/src/sst/aws/Topic.ts +0 -68
- package/src/sst/aws/bootstrap/handler.ts +0 -119
- package/src/sst/aws/ses.ts +0 -132
- package/src/sst/errors.ts +0 -65
- package/src/sst/fromManifest.ts +0 -1116
- package/src/sst/overrides.ts +0 -133
- package/src/sst/upstash.d.ts +0 -38
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Checked by `ts:check:sst`; vitest ignores it.
|
|
3
3
|
|
|
4
4
|
import { App } from '../App';
|
|
5
|
-
import { Function } from '../
|
|
6
|
-
import { Storage } from '../
|
|
5
|
+
import { Function } from '../Function';
|
|
6
|
+
import { Storage } from '../Storage';
|
|
7
7
|
|
|
8
8
|
const stack = new App({
|
|
9
9
|
name: 'a',
|
package/src/sst/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { App, type AppProps, type StageValues } from './App';
|
|
2
1
|
export {
|
|
3
2
|
Api,
|
|
4
3
|
type ApiAuthorizers,
|
|
@@ -7,77 +6,18 @@ export {
|
|
|
7
6
|
type JwtAuthorizer,
|
|
8
7
|
type LambdaAuthorizer,
|
|
9
8
|
type Route,
|
|
10
|
-
} from './
|
|
11
|
-
export {
|
|
12
|
-
Cache,
|
|
13
|
-
CacheNeedsDatabase,
|
|
14
|
-
CacheNeedsProvider,
|
|
15
|
-
CacheNeedsVpc,
|
|
16
|
-
type CacheProps,
|
|
17
|
-
} from './aws/Cache';
|
|
18
|
-
export { Credential, type CredentialProps } from './aws/Credential';
|
|
9
|
+
} from './Api';
|
|
10
|
+
export { App, type AppProps, type StageValues } from './App';
|
|
19
11
|
export {
|
|
20
12
|
Cron,
|
|
21
13
|
type CronExpression,
|
|
22
14
|
type CronProps,
|
|
23
15
|
type CronRate,
|
|
24
16
|
type CronSchedule,
|
|
25
|
-
} from './
|
|
26
|
-
export {
|
|
27
|
-
Database,
|
|
28
|
-
DatabaseNeedsVpc,
|
|
29
|
-
type DatabaseProps,
|
|
30
|
-
} from './aws/Database';
|
|
31
|
-
export {
|
|
32
|
-
bootstrapEvent,
|
|
33
|
-
DatabaseBootstrap,
|
|
34
|
-
} from './aws/DatabaseBootstrap';
|
|
35
|
-
export { DatabaseReader, DatabaseSchema } from './aws/DerivedDatabase';
|
|
36
|
-
export { Email, EmailNeedsUrl, type EmailProps } from './aws/Email';
|
|
37
|
-
export { Encryption, type EncryptionProps } from './aws/Encryption';
|
|
38
|
-
export { FileServer, type FileServerProps } from './aws/FileServer';
|
|
39
|
-
export { Function, type FunctionProps } from './aws/Function';
|
|
40
|
-
export {
|
|
41
|
-
ObjectStorage,
|
|
42
|
-
type ObjectStorageProps,
|
|
43
|
-
} from './aws/ObjectStorage';
|
|
44
|
-
export { fifoName, Queue, type QueueProps } from './aws/Queue';
|
|
45
|
-
export { Secret, type SecretProps } from './aws/Secret';
|
|
46
|
-
export { StaticSite, type StaticSiteProps } from './aws/StaticSite';
|
|
47
|
-
/** @deprecated renamed to `ObjectStorage`, matching the construct that declares it. */
|
|
48
|
-
export { Storage, type StorageProps } from './aws/Storage';
|
|
49
|
-
export {
|
|
50
|
-
NoSmtpEndpoint,
|
|
51
|
-
SMTP_PORT,
|
|
52
|
-
SMTP_REGIONS,
|
|
53
|
-
sesSmtpUrl,
|
|
54
|
-
smtpEndpoint,
|
|
55
|
-
smtpPassword,
|
|
56
|
-
} from './aws/ses';
|
|
57
|
-
export { Topic, type TopicProps } from './aws/Topic';
|
|
58
|
-
export {
|
|
59
|
-
ProvidesMismatch,
|
|
60
|
-
UnknownDeclarationKind,
|
|
61
|
-
UnresolvedDependency,
|
|
62
|
-
} from './errors';
|
|
63
|
-
export {
|
|
64
|
-
assertProvides,
|
|
65
|
-
describeRoutes,
|
|
66
|
-
fromManifest,
|
|
67
|
-
isServed,
|
|
68
|
-
type ProvisionContext,
|
|
69
|
-
type Provisioned,
|
|
70
|
-
type ProvisionedManifest,
|
|
71
|
-
provisionerFor,
|
|
72
|
-
type ResolvedEdges,
|
|
73
|
-
resolveEdges,
|
|
74
|
-
siteEnvironment,
|
|
75
|
-
} from './fromManifest';
|
|
17
|
+
} from './Cron';
|
|
18
|
+
export { Function, type FunctionProps } from './Function';
|
|
76
19
|
export { type GkmLinkable, ResourceType } from './Linkable';
|
|
77
|
-
export {
|
|
78
|
-
export type {
|
|
79
|
-
ManifestBackends,
|
|
80
|
-
ManifestOverrides,
|
|
81
|
-
OverrideFor,
|
|
82
|
-
} from './overrides';
|
|
20
|
+
export { Queue, type QueueProps } from './Queue';
|
|
83
21
|
export { Stack, type StackType } from './Stack';
|
|
22
|
+
export { Storage, type StorageProps } from './Storage';
|
|
23
|
+
export { Topic, type TopicProps } from './Topic';
|
package/src/sst/naming.ts
CHANGED
|
@@ -1,44 +1,23 @@
|
|
|
1
|
-
import { kebabCase, scopedName } from '@geekmidas/manifest';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Kebab-cases an identifier: `userName` → `user-name`, `my_handler` →
|
|
5
|
-
* `my-handler`, acronym-aware (`APIKey` → `api-key`
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Re-exported from `@geekmidas/manifest` rather than implemented here. It used
|
|
9
|
-
* to be implemented here, beside a second spelling of the same rule in the
|
|
10
|
-
* manifest — which agreed on every id anyone had tried and disagreed on
|
|
11
|
-
* `S3Bucket`.
|
|
12
|
-
*/
|
|
13
|
-
export const kebab = kebabCase;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A kebab-cased, prefixed physical resource name — `[stage, app]` and the
|
|
17
|
-
* resource, joined and lower-cased, without doubling a prefix the resource
|
|
18
|
-
* already carries.
|
|
19
|
-
*
|
|
20
|
-
* The same rule every other target names by: this is `cloudName` for a caller
|
|
21
|
-
* whose prefix is a list, because an SST stack contributes a segment of its
|
|
22
|
-
* own. A construct is named the same thing here and on Dokploy, which is the
|
|
23
|
-
* property that lets one name be read across providers.
|
|
3
|
+
* `my-handler`, and acronym-aware (`APIKey` → `api-key`, `XMLParser` →
|
|
4
|
+
* `xml-parser`).
|
|
24
5
|
*/
|
|
25
|
-
export
|
|
6
|
+
export function kebab(value: string): string {
|
|
7
|
+
return value
|
|
8
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
9
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
10
|
+
.replace(/[\s_]+/g, '-')
|
|
11
|
+
.toLowerCase();
|
|
12
|
+
}
|
|
26
13
|
|
|
27
14
|
/**
|
|
28
|
-
*
|
|
29
|
-
* `
|
|
30
|
-
*
|
|
31
|
-
* Every connection string this package composes carries the region explicitly,
|
|
32
|
-
* because `AWS_REGION` inside a Lambda is the *function's* region and not the
|
|
33
|
-
* resource's. A cross-region queue then works right up until it doesn't, and
|
|
34
|
-
* fails at runtime with nothing in the URL to explain why.
|
|
35
|
-
*
|
|
36
|
-
* Returns `undefined` for the ARN shapes that carry no region — an IAM ARN, or
|
|
37
|
-
* anything that is not an ARN at all — so a caller omits the parameter rather
|
|
38
|
-
* than writing an empty one.
|
|
15
|
+
* Builds a kebab-cased, prefixed physical resource name. The `prefix` parts
|
|
16
|
+
* (e.g. `[stage, name]`) are joined and lower-cased; if `resource` already
|
|
17
|
+
* starts with that prefix it is returned as-is (kebab-cased) to avoid doubling.
|
|
39
18
|
*/
|
|
40
|
-
export function
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
return
|
|
19
|
+
export function prefixedName(prefix: string[], resource: string): string {
|
|
20
|
+
const joined = prefix.join('-').toLowerCase();
|
|
21
|
+
const name = kebab(resource);
|
|
22
|
+
return name.startsWith(joined) ? name : `${joined}-${name}`;
|
|
44
23
|
}
|
package/src/sst/tsconfig.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"//": "Project config for the source-only `src/sst`
|
|
2
|
+
"//": "Project config for the source-only `src/sst` constructs. It lives here (not at the package root) so editors pick it as the NEAREST tsconfig for these files and resolve the ambient `sst`/`aws`/`$util` globals from `.sst/platform` plus node's `process` — the package's main tsconfig.json excludes `src/sst`. Compiler options are shared via `../../tsconfig.sst.json`; this file only adds the file set. Run via `pnpm --filter @geekmidas/cloud ts:check:sst` after `sst install`.",
|
|
3
3
|
"extends": "../../tsconfig.sst.json",
|
|
4
|
-
"include": ["**/*", "
|
|
4
|
+
"include": ["**/*", "../../.sst/platform/config.d.ts"]
|
|
5
5
|
}
|
package/dist/utils/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["os","snakecase"],"sources":["../../src/utils/index.ts"],"sourcesContent":["import os from 'node:os';\nimport snakecase from 'lodash.snakecase';\n\nexport function getLocalIpAddress() {\n\tconst networkInterfaces = os.networkInterfaces();\n\tfor (const interfaceName in networkInterfaces) {\n\t\tconst addresses = networkInterfaces[interfaceName] || [];\n\t\tfor (const addressInfo of addresses) {\n\t\t\t// Look for an IPv4 address that is not internal (loopback)\n\t\t\tif (addressInfo.family === 'IPv4' && !addressInfo.internal) {\n\t\t\t\treturn addressInfo.address;\n\t\t\t}\n\t\t}\n\t}\n\treturn null; // No suitable IP address found\n}\n\nexport function environmentCase(name: string) {\n\treturn snakecase(name)\n\t\t.toUpperCase()\n\t\t.replace(/_\\d+/g, (r) => {\n\t\t\treturn r.replace('_', '');\n\t\t});\n}\nexport enum ResourceType {\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tObjectStorage = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTObjectStorage = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n}\n\nconst secret = (name: string, value: Secret) => ({\n\t[environmentCase(name)]: value.value,\n});\nconst postgres = (key: string, value: Postgres) => {\n\tconst prefix = `${environmentCase(key)}`;\n\treturn {\n\t\t[`${prefix}_NAME`]: value.database,\n\t\t[`${prefix}_HOST`]: value.host,\n\t\t[`${prefix}_PASSWORD`]: value.password,\n\t\t[`${prefix}_PORT`]: value.port,\n\t\t[`${prefix}_USERNAME`]: value.username,\n\t};\n};\n\nconst bucket = (name: string, value: Bucket) => {\n\tconst prefix = `${environmentCase(name)}`;\n\treturn {\n\t\t[`${prefix}_NAME`]: value.name,\n\t};\n};\n\nconst topic = (name: string, value: SnsTopic) => {\n\tconst prefix = `${environmentCase(name)}`;\n\tconst key = `${prefix}_ARN`;\n\n\treturn {\n\t\t[key]: value.arn,\n\t};\n};\n\nconst noop = (_name: string, _value: any) => ({});\n\nconst processors: Record<ResourceType, ResourceProcessor<any>> = {\n\t[ResourceType.ApiGatewayV2]: noop,\n\t[ResourceType.Function]: noop,\n\t[ResourceType.Vpc]: noop,\n\t[ResourceType.Secret]: secret,\n\t[ResourceType.Postgres]: postgres,\n\t[ResourceType.ObjectStorage]: bucket,\n\n\t[ResourceType.SSTSecret]: secret,\n\t[ResourceType.SSTObjectStorage]: bucket,\n\t[ResourceType.SSTFunction]: noop,\n\t[ResourceType.SSTPostgres]: postgres,\n\t[ResourceType.SSTApiGatewayV2]: noop,\n\t[ResourceType.SnsTopic]: topic,\n};\n\nexport function buildResourceEnv(\n\trecord: Record<string, Resource | string>,\n): Record<string, string> {\n\tconst env: Record<string, string> = {};\n\tfor (const [k, value] of Object.entries(record)) {\n\t\tif (typeof value === 'string') {\n\t\t\tenv[environmentCase(k)] = value;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst processor = processors[value.type];\n\t\tif (processor) {\n\t\t\tObject.assign(env, processor(k, value));\n\t\t} else {\n\t\t}\n\t}\n\n\treturn env;\n}\n\n/**\n * SST links a resource under one of two spellings — `sst.aws.Bucket` when it\n * comes from the state file, `sst:aws:Bucket` when it comes from the runtime —\n * and `processors` has always handled both. Only the dotted half was admitted\n * here, so the colon half could not be passed to `buildResourceEnv` without a\n * cast, and `SnsTopic` was missing from `Resource` altogether despite being the\n * only thing that produces `*_ARN`.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\nexport type Postgres = {\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tusername: string;\n};\n\nexport type Function = {\n\tname: string;\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n};\n\nexport type Bucket = {\n\tname: string;\n\ttype: ResourceType.ObjectStorage | ResourceType.SSTObjectStorage;\n};\n\nexport type SnsTopic = {\n\tarn: string;\n\ttype: ResourceType.SnsTopic;\n};\n\nexport type Vpc = {\n\tbastion: string;\n\ttype: ResourceType.Vpc;\n};\n\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\nexport type Resource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| SnsTopic\n\t| Vpc\n\t| Secret;\n\nexport type ResourceProcessor<K extends Resource> = (\n\tname: string,\n\tvalue: K,\n) => Record<string, string | number>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,oBAAoB;CACnC,MAAM,oBAAoBA,QAAAA,QAAG,kBAAkB;CAC/C,KAAK,MAAM,iBAAiB,mBAAmB;EAC9C,MAAM,YAAY,kBAAkB,kBAAkB,CAAC;EACvD,KAAK,MAAM,eAAe,WAEzB,IAAI,YAAY,WAAW,UAAU,CAAC,YAAY,UACjD,OAAO,YAAY;CAGtB;CACA,OAAO;AACR;AAEA,SAAgB,gBAAgB,MAAc;CAC7C,QAAA,GAAOC,iBAAAA,QAAAA,CAAU,IAAI,CAAC,CACpB,YAAY,CAAC,CACb,QAAQ,UAAU,MAAM;EACxB,OAAO,EAAE,QAAQ,KAAK,EAAE;CACzB,CAAC;AACH;AACA,IAAY,eAAL,yBAAA,cAAA;CACN,aAAA,kBAAA;CACA,aAAA,cAAA;CACA,aAAA,cAAA;CACA,aAAA,mBAAA;CACA,aAAA,SAAA;CACA,aAAA,YAAA;CACA,aAAA,eAAA;CACA,aAAA,iBAAA;CACA,aAAA,qBAAA;CACA,aAAA,iBAAA;CACA,aAAA,sBAAA;CACA,aAAA,cAAA;;AACD,EAAA,CAAA,CAAA;AAEA,MAAM,UAAU,MAAc,WAAmB,GAC/C,gBAAgB,IAAI,IAAI,MAAM,MAChC;AACA,MAAM,YAAY,KAAa,UAAoB;CAClD,MAAM,SAAS,GAAG,gBAAgB,GAAG;CACrC,OAAO;GACL,GAAG,OAAO,SAAS,MAAM;GACzB,GAAG,OAAO,SAAS,MAAM;GACzB,GAAG,OAAO,aAAa,MAAM;GAC7B,GAAG,OAAO,SAAS,MAAM;GACzB,GAAG,OAAO,aAAa,MAAM;CAC/B;AACD;AAEA,MAAM,UAAU,MAAc,UAAkB;CAE/C,OAAO,GACL,GAAG,GAFa,gBAAgB,IAAI,IAE1B,SAAS,MAAM,KAC3B;AACD;AAEA,MAAM,SAAS,MAAc,UAAoB;CAIhD,OAAO,GACL,GAHa,GADG,gBAAgB,IAAI,IAChB,QAGd,MAAM,IACd;AACD;AAEA,MAAM,QAAQ,OAAe,YAAiB,CAAC;AAE/C,MAAM,aAA2D;EACnC,yBAAA;EACJ,qBAAA;EACL,gBAAA;EACG,mBAAA;EACE,qBAAA;EACK,mBAAA;EAEJ,mBAAA;EACO,mBAAA;EACL,qBAAA;EACA,qBAAA;EACI,yBAAA;EACP,qBAAA;AAC1B;AAEA,SAAgB,iBACf,QACyB;CACzB,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,CAAC,GAAG,UAAU,OAAO,QAAQ,MAAM,GAAG;EAChD,IAAI,OAAO,UAAU,UAAU;GAC9B,IAAI,gBAAgB,CAAC,KAAK;GAC1B;EACD;EAEA,MAAM,YAAY,WAAW,MAAM;EACnC,IAAI,WACH,OAAO,OAAO,KAAK,UAAU,GAAG,KAAK,CAAC;CAGxC;CAEA,OAAO;AACR"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";wBAGgB;wBAcA,gBAAgB;oBAOpB;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;wBAmDe,iBACf,QAAQ,eAAe,qBACrB;;;;;;;;;YA0BS;EACX,MAAM,aAAa,eAAe,aAAa;EAC/C;;YAGW;EACX;EACA;EACA;EACA;EACA,MAAM,aAAa,WAAW,aAAa;EAC3C;;YAGW;EACX;EACA,MAAM,aAAa,WAAW,aAAa;;YAGhC;EACX;EACA,MAAM,aAAa,gBAAgB,aAAa;;YAGrC;EACX;EACA,MAAM,aAAa;;YAGR;EACX;EACA,MAAM,aAAa;;YAGR;EACX,MAAM,aAAa,SAAS,aAAa;EACzC;;YAGW,WACT,eACA,WACA,WACA,SACA,WACA,MACA;YAES,kBAAkB,UAAU,aACvC,cACA,OAAO,MACH"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/utils/index.ts"],"mappings":";wBAGgB;wBAcA,gBAAgB;oBAOpB;EACX;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;wBAmDe,iBACf,QAAQ,eAAe,qBACrB;;;;;;;;;YA0BS;EACX,MAAM,aAAa,eAAe,aAAa;EAC/C;;YAGW;EACX;EACA;EACA;EACA;EACA,MAAM,aAAa,WAAW,aAAa;EAC3C;;YAGW;EACX;EACA,MAAM,aAAa,WAAW,aAAa;;YAGhC;EACX;EACA,MAAM,aAAa,gBAAgB,aAAa;;YAGrC;EACX;EACA,MAAM,aAAa;;YAGR;EACX;EACA,MAAM,aAAa;;YAGR;EACX,MAAM,aAAa,SAAS,aAAa;EACzC;;YAGW,WACT,eACA,WACA,WACA,SACA,WACA,MACA;YAES,kBAAkB,UAAU,aACvC,cACA,OAAO,MACH"}
|
package/dist/utils/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["import os from 'node:os';\nimport snakecase from 'lodash.snakecase';\n\nexport function getLocalIpAddress() {\n\tconst networkInterfaces = os.networkInterfaces();\n\tfor (const interfaceName in networkInterfaces) {\n\t\tconst addresses = networkInterfaces[interfaceName] || [];\n\t\tfor (const addressInfo of addresses) {\n\t\t\t// Look for an IPv4 address that is not internal (loopback)\n\t\t\tif (addressInfo.family === 'IPv4' && !addressInfo.internal) {\n\t\t\t\treturn addressInfo.address;\n\t\t\t}\n\t\t}\n\t}\n\treturn null; // No suitable IP address found\n}\n\nexport function environmentCase(name: string) {\n\treturn snakecase(name)\n\t\t.toUpperCase()\n\t\t.replace(/_\\d+/g, (r) => {\n\t\t\treturn r.replace('_', '');\n\t\t});\n}\nexport enum ResourceType {\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tObjectStorage = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTObjectStorage = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n}\n\nconst secret = (name: string, value: Secret) => ({\n\t[environmentCase(name)]: value.value,\n});\nconst postgres = (key: string, value: Postgres) => {\n\tconst prefix = `${environmentCase(key)}`;\n\treturn {\n\t\t[`${prefix}_NAME`]: value.database,\n\t\t[`${prefix}_HOST`]: value.host,\n\t\t[`${prefix}_PASSWORD`]: value.password,\n\t\t[`${prefix}_PORT`]: value.port,\n\t\t[`${prefix}_USERNAME`]: value.username,\n\t};\n};\n\nconst bucket = (name: string, value: Bucket) => {\n\tconst prefix = `${environmentCase(name)}`;\n\treturn {\n\t\t[`${prefix}_NAME`]: value.name,\n\t};\n};\n\nconst topic = (name: string, value: SnsTopic) => {\n\tconst prefix = `${environmentCase(name)}`;\n\tconst key = `${prefix}_ARN`;\n\n\treturn {\n\t\t[key]: value.arn,\n\t};\n};\n\nconst noop = (_name: string, _value: any) => ({});\n\nconst processors: Record<ResourceType, ResourceProcessor<any>> = {\n\t[ResourceType.ApiGatewayV2]: noop,\n\t[ResourceType.Function]: noop,\n\t[ResourceType.Vpc]: noop,\n\t[ResourceType.Secret]: secret,\n\t[ResourceType.Postgres]: postgres,\n\t[ResourceType.ObjectStorage]: bucket,\n\n\t[ResourceType.SSTSecret]: secret,\n\t[ResourceType.SSTObjectStorage]: bucket,\n\t[ResourceType.SSTFunction]: noop,\n\t[ResourceType.SSTPostgres]: postgres,\n\t[ResourceType.SSTApiGatewayV2]: noop,\n\t[ResourceType.SnsTopic]: topic,\n};\n\nexport function buildResourceEnv(\n\trecord: Record<string, Resource | string>,\n): Record<string, string> {\n\tconst env: Record<string, string> = {};\n\tfor (const [k, value] of Object.entries(record)) {\n\t\tif (typeof value === 'string') {\n\t\t\tenv[environmentCase(k)] = value;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst processor = processors[value.type];\n\t\tif (processor) {\n\t\t\tObject.assign(env, processor(k, value));\n\t\t} else {\n\t\t}\n\t}\n\n\treturn env;\n}\n\n/**\n * SST links a resource under one of two spellings — `sst.aws.Bucket` when it\n * comes from the state file, `sst:aws:Bucket` when it comes from the runtime —\n * and `processors` has always handled both. Only the dotted half was admitted\n * here, so the colon half could not be passed to `buildResourceEnv` without a\n * cast, and `SnsTopic` was missing from `Resource` altogether despite being the\n * only thing that produces `*_ARN`.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: string;\n};\n\nexport type Postgres = {\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tusername: string;\n};\n\nexport type Function = {\n\tname: string;\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n};\n\nexport type Bucket = {\n\tname: string;\n\ttype: ResourceType.ObjectStorage | ResourceType.SSTObjectStorage;\n};\n\nexport type SnsTopic = {\n\tarn: string;\n\ttype: ResourceType.SnsTopic;\n};\n\nexport type Vpc = {\n\tbastion: string;\n\ttype: ResourceType.Vpc;\n};\n\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\nexport type Resource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| SnsTopic\n\t| Vpc\n\t| Secret;\n\nexport type ResourceProcessor<K extends Resource> = (\n\tname: string,\n\tvalue: K,\n) => Record<string, string | number>;\n"],"mappings":";;;AAGA,SAAgB,oBAAoB;CACnC,MAAM,oBAAoB,GAAG,kBAAkB;CAC/C,KAAK,MAAM,iBAAiB,mBAAmB;EAC9C,MAAM,YAAY,kBAAkB,kBAAkB,CAAC;EACvD,KAAK,MAAM,eAAe,WAEzB,IAAI,YAAY,WAAW,UAAU,CAAC,YAAY,UACjD,OAAO,YAAY;CAGtB;CACA,OAAO;AACR;AAEA,SAAgB,gBAAgB,MAAc;CAC7C,OAAO,UAAU,IAAI,CAAC,CACpB,YAAY,CAAC,CACb,QAAQ,UAAU,MAAM;EACxB,OAAO,EAAE,QAAQ,KAAK,EAAE;CACzB,CAAC;AACH;AACA,IAAY,eAAL,yBAAA,cAAA;CACN,aAAA,kBAAA;CACA,aAAA,cAAA;CACA,aAAA,cAAA;CACA,aAAA,mBAAA;CACA,aAAA,SAAA;CACA,aAAA,YAAA;CACA,aAAA,eAAA;CACA,aAAA,iBAAA;CACA,aAAA,qBAAA;CACA,aAAA,iBAAA;CACA,aAAA,sBAAA;CACA,aAAA,cAAA;;AACD,EAAA,CAAA,CAAA;AAEA,MAAM,UAAU,MAAc,WAAmB,GAC/C,gBAAgB,IAAI,IAAI,MAAM,MAChC;AACA,MAAM,YAAY,KAAa,UAAoB;CAClD,MAAM,SAAS,GAAG,gBAAgB,GAAG;CACrC,OAAO;GACL,GAAG,OAAO,SAAS,MAAM;GACzB,GAAG,OAAO,SAAS,MAAM;GACzB,GAAG,OAAO,aAAa,MAAM;GAC7B,GAAG,OAAO,SAAS,MAAM;GACzB,GAAG,OAAO,aAAa,MAAM;CAC/B;AACD;AAEA,MAAM,UAAU,MAAc,UAAkB;CAE/C,OAAO,GACL,GAAG,GAFa,gBAAgB,IAAI,IAE1B,SAAS,MAAM,KAC3B;AACD;AAEA,MAAM,SAAS,MAAc,UAAoB;CAIhD,OAAO,GACL,GAHa,GADG,gBAAgB,IAAI,IAChB,QAGd,MAAM,IACd;AACD;AAEA,MAAM,QAAQ,OAAe,YAAiB,CAAC;AAE/C,MAAM,aAA2D;EACnC,yBAAA;EACJ,qBAAA;EACL,gBAAA;EACG,mBAAA;EACE,qBAAA;EACK,mBAAA;EAEJ,mBAAA;EACO,mBAAA;EACL,qBAAA;EACA,qBAAA;EACI,yBAAA;EACP,qBAAA;AAC1B;AAEA,SAAgB,iBACf,QACyB;CACzB,MAAM,MAA8B,CAAC;CACrC,KAAK,MAAM,CAAC,GAAG,UAAU,OAAO,QAAQ,MAAM,GAAG;EAChD,IAAI,OAAO,UAAU,UAAU;GAC9B,IAAI,gBAAgB,CAAC,KAAK;GAC1B;EACD;EAEA,MAAM,YAAY,WAAW,MAAM;EACnC,IAAI,WACH,OAAO,OAAO,KAAK,UAAU,GAAG,KAAK,CAAC;CAGxC;CAEA,OAAO;AACR"}
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import { dynamic, type Input, type Output } from '@pulumi/pulumi';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A Dokploy application, as a Pulumi resource.
|
|
5
|
-
*
|
|
6
|
-
* **A prototype, and the point of it is the shape rather than the coverage.**
|
|
7
|
-
* One resource, to see whether wrapping Dokploy's REST API in a dynamic provider
|
|
8
|
-
* is worth doing for the rest — because if it is, a whole subsystem goes away.
|
|
9
|
-
*
|
|
10
|
-
* ## Why this is worth trying
|
|
11
|
-
*
|
|
12
|
-
* `packages/cli/src/deploy/` is a deployment engine written by hand: it calls
|
|
13
|
-
* the API, and it remembers what it created in `deploy/state.ts` and
|
|
14
|
-
* `SSMStateProvider` so the next deploy can find the same resources. That second
|
|
15
|
-
* half is the interesting one, because *remembering what you created* is the
|
|
16
|
-
* entire job of a Pulumi state file. A provider does not need it.
|
|
17
|
-
*
|
|
18
|
-
* What else falls out: `pulumi preview` starts working for the server target,
|
|
19
|
-
* and `fromManifest` becomes one shape across both targets — a table of
|
|
20
|
-
* provisioners — rather than an SST adapter beside a bespoke engine.
|
|
21
|
-
*
|
|
22
|
-
* ## Why it is a dynamic provider and not a real one
|
|
23
|
-
*
|
|
24
|
-
* A real Pulumi provider is a plugin binary with a schema, usually generated
|
|
25
|
-
* from a Terraform provider that does not exist here. A dynamic provider is a
|
|
26
|
-
* TypeScript object with `create`/`read`/`update`/`delete`, running in-process
|
|
27
|
-
* during the deploy. SST itself uses this exact escape hatch wherever official
|
|
28
|
-
* coverage stops — `vercel/providers/dns-record.ts`,
|
|
29
|
-
* `cloudflare/providers/kv-data.ts` — which is the precedent worth leaning on.
|
|
30
|
-
*
|
|
31
|
-
* ## The three things that make it risky
|
|
32
|
-
*
|
|
33
|
-
* 1. **The provider is serialised into state.** Pulumi captures the functions
|
|
34
|
-
* below and stores them, so they must be self-contained — no reaching for an
|
|
35
|
-
* import from the surrounding module at call time. That is why the API token
|
|
36
|
-
* is an *input* rather than something closed over, and why `fetch` is used
|
|
37
|
-
* directly instead of `DokployApi`, which would have to serialise with it.
|
|
38
|
-
* 2. **`delete` runs on destroy, and orphans are silent.** Today's engine fails
|
|
39
|
-
* loudly when it cannot find something; a provider that gets destroy wrong
|
|
40
|
-
* leaves resources behind that Pulumi believes it removed. This is the half
|
|
41
|
-
* to be most careful with, and the reason a prototype exists at all.
|
|
42
|
-
* 3. **`diff` is yours.** Without it, preview cannot say what a change will do —
|
|
43
|
-
* which is one of the main reasons for doing this.
|
|
44
|
-
*
|
|
45
|
-
* ## Not verified
|
|
46
|
-
*
|
|
47
|
-
* No Dokploy instance has run this. The shape type-checks and the decisions are
|
|
48
|
-
* assertable; nothing has been created or destroyed against a real server.
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
interface ApplicationInputs {
|
|
52
|
-
/** Where the Dokploy server answers, e.g. `https://dokploy.example.com`. */
|
|
53
|
-
endpoint: string;
|
|
54
|
-
/**
|
|
55
|
-
* The API token.
|
|
56
|
-
*
|
|
57
|
-
* An input rather than a captured variable, because the provider's functions
|
|
58
|
-
* are serialised into state and a closure over module scope does not survive
|
|
59
|
-
* that. SST's own dynamic providers pass credentials the same way.
|
|
60
|
-
*/
|
|
61
|
-
apiToken: string;
|
|
62
|
-
name: string;
|
|
63
|
-
projectId: string;
|
|
64
|
-
environmentId: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface ApplicationOutputs extends ApplicationInputs {
|
|
68
|
-
applicationId: string;
|
|
69
|
-
appName: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Dokploy's app name rule, applied where the name is decided.
|
|
74
|
-
*
|
|
75
|
-
* The existing client does this inline at the create call; here it is a function
|
|
76
|
-
* because `diff` has to ask whether a *changed* name produces a changed app
|
|
77
|
-
* name, and duplicating the expression is how those two answers drift apart.
|
|
78
|
-
*/
|
|
79
|
-
export function appNameFor(name: string): string {
|
|
80
|
-
return name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* What a change costs — pure, so preview's behaviour can be asserted without a
|
|
85
|
-
* Dokploy server.
|
|
86
|
-
*
|
|
87
|
-
* The name is the interesting one: Dokploy derives `appName` from it, and
|
|
88
|
-
* changing that is not an update but a different application, so the old one has
|
|
89
|
-
* to go. Saying so here is what makes `pulumi preview` warn *before* the
|
|
90
|
-
* destroy rather than reporting it after.
|
|
91
|
-
*/
|
|
92
|
-
export function diffApplication(
|
|
93
|
-
olds: { name: string; projectId: string; environmentId: string },
|
|
94
|
-
news: { name: string; projectId: string; environmentId: string },
|
|
95
|
-
): { changes: boolean; replaces: string[]; deleteBeforeReplace: boolean } {
|
|
96
|
-
const replaces: string[] = [];
|
|
97
|
-
|
|
98
|
-
if (appNameFor(olds.name) !== appNameFor(news.name)) replaces.push('name');
|
|
99
|
-
if (olds.projectId !== news.projectId) replaces.push('projectId');
|
|
100
|
-
if (olds.environmentId !== news.environmentId) replaces.push('environmentId');
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
changes: replaces.length > 0 || olds.name !== news.name,
|
|
104
|
-
replaces,
|
|
105
|
-
// Create the replacement before removing the old one. A Dokploy project
|
|
106
|
-
// can hold both for a moment; it cannot hold a gap where the application
|
|
107
|
-
// used to be.
|
|
108
|
-
deleteBeforeReplace: false,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const provider: dynamic.ResourceProvider<
|
|
113
|
-
ApplicationInputs,
|
|
114
|
-
ApplicationOutputs
|
|
115
|
-
> = {
|
|
116
|
-
async create(inputs) {
|
|
117
|
-
const application = await call<{
|
|
118
|
-
applicationId: string;
|
|
119
|
-
appName: string;
|
|
120
|
-
}>(inputs, 'application.create', {
|
|
121
|
-
name: inputs.name,
|
|
122
|
-
projectId: inputs.projectId,
|
|
123
|
-
environmentId: inputs.environmentId,
|
|
124
|
-
appName: appNameFor(inputs.name),
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
// Pulumi's own id for the resource. Using Dokploy's makes the two
|
|
129
|
-
// agree, so a state file read by a human names the same thing the
|
|
130
|
-
// Dokploy UI does.
|
|
131
|
-
id: application.applicationId,
|
|
132
|
-
outs: { ...inputs, ...application },
|
|
133
|
-
};
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Refresh from the server.
|
|
138
|
-
*
|
|
139
|
-
* Returning no id is how a provider says "this is gone", which is what
|
|
140
|
-
* lets `pulumi refresh` notice something deleted in the Dokploy UI rather
|
|
141
|
-
* than failing on the next update against a resource that is not there.
|
|
142
|
-
*/
|
|
143
|
-
async read(id, props) {
|
|
144
|
-
const application = await call<{
|
|
145
|
-
applicationId: string;
|
|
146
|
-
appName: string;
|
|
147
|
-
} | null>(
|
|
148
|
-
props as ApplicationInputs,
|
|
149
|
-
`application.one?applicationId=${id}`,
|
|
150
|
-
undefined,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
if (!application) return { id: undefined };
|
|
154
|
-
|
|
155
|
-
return { id, props: { ...(props as ApplicationOutputs), ...application } };
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* What a change costs.
|
|
160
|
-
*
|
|
161
|
-
* The name is the interesting one: Dokploy derives `appName` from it, and
|
|
162
|
-
* changing that is not an update — it is a different application, so the
|
|
163
|
-
* old one has to go. Saying so here is what makes `pulumi preview` warn
|
|
164
|
-
* before the destroy rather than after.
|
|
165
|
-
*/
|
|
166
|
-
async diff(_id, olds, news) {
|
|
167
|
-
return diffApplication(olds, news);
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
async update(id, _olds, news) {
|
|
171
|
-
await call(news, 'application.update', {
|
|
172
|
-
applicationId: id,
|
|
173
|
-
name: news.name,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
outs: { ...news, applicationId: id, appName: appNameFor(news.name) },
|
|
178
|
-
};
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Remove it, and treat "already gone" as success.
|
|
183
|
-
*
|
|
184
|
-
* A destroy that fails because somebody removed the application by hand
|
|
185
|
-
* leaves the stack unable to make progress, which is worse than the thing
|
|
186
|
-
* it is protecting against — the resource is absent either way, which is
|
|
187
|
-
* what was asked for.
|
|
188
|
-
*/
|
|
189
|
-
async delete(id, props) {
|
|
190
|
-
try {
|
|
191
|
-
await call(props, 'application.remove', { applicationId: id });
|
|
192
|
-
} catch (error) {
|
|
193
|
-
if (!isNotFound(error)) throw error;
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* A Dokploy API call that answered with an error status.
|
|
200
|
-
*
|
|
201
|
-
* Defined here, beside the provider, rather than imported: the provider's
|
|
202
|
-
* functions are serialised into state, and Pulumi's closure serialiser
|
|
203
|
-
* captures a class declared in the same module by value — once, shared by
|
|
204
|
-
* every function that refers to it, so `instanceof` still holds in the
|
|
205
|
-
* deployed provider. An imported class would have to be resolvable as a
|
|
206
|
-
* module where the provider runs, which is the obscure failure the note on
|
|
207
|
-
* `call` below is about.
|
|
208
|
-
*
|
|
209
|
-
* Serialisation rewrites the class into a plain function and drops its link to
|
|
210
|
-
* `Error.prototype`, so the constructor sets `message` and `stack` itself and
|
|
211
|
-
* the class says how to print itself. `Application.provider.spec.ts` runs the
|
|
212
|
-
* serialised provider to keep all of this true.
|
|
213
|
-
*/
|
|
214
|
-
export class DokployCallFailed extends Error {
|
|
215
|
-
constructor(
|
|
216
|
-
readonly path: string,
|
|
217
|
-
readonly status: number,
|
|
218
|
-
readonly statusText: string,
|
|
219
|
-
readonly detail: string,
|
|
220
|
-
) {
|
|
221
|
-
const message = `Dokploy ${path} failed: ${status} ${statusText}${detail ? ` — ${detail}` : ''}. Check the endpoint and API token, and Dokploy's own logs for the request.`;
|
|
222
|
-
super(message);
|
|
223
|
-
// Serialised, this constructor becomes a plain function whose super call
|
|
224
|
-
// does not initialise `this`: without these the provider host, which
|
|
225
|
-
// reports `e.message` and logs `${e}: ${e.stack}`, would show nothing.
|
|
226
|
-
this.message = message;
|
|
227
|
-
Error.captureStackTrace?.(this, DokployCallFailed);
|
|
228
|
-
this.name = 'DokployCallFailed';
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/** What `${error}` prints once serialisation has dropped Error's own. */
|
|
232
|
-
override toString(): string {
|
|
233
|
-
return `${this.name}: ${this.message}`;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* One call to Dokploy.
|
|
239
|
-
*
|
|
240
|
-
* Written out rather than reusing `DokployApi` because the provider's functions
|
|
241
|
-
* are serialised into state: a class imported from another module would have to
|
|
242
|
-
* serialise too, and the failure when it cannot is obscure. `fetch` is a global.
|
|
243
|
-
*/
|
|
244
|
-
async function call<T>(
|
|
245
|
-
auth: { endpoint: string; apiToken: string },
|
|
246
|
-
path: string,
|
|
247
|
-
body?: Record<string, unknown>,
|
|
248
|
-
): Promise<T> {
|
|
249
|
-
const response = await fetch(`${auth.endpoint}/api/trpc/${path}`, {
|
|
250
|
-
method: body ? 'POST' : 'GET',
|
|
251
|
-
headers: {
|
|
252
|
-
'x-api-key': auth.apiToken,
|
|
253
|
-
'content-type': 'application/json',
|
|
254
|
-
},
|
|
255
|
-
...(body ? { body: JSON.stringify(body) } : {}),
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
if (!response.ok) {
|
|
259
|
-
const detail = await response.text().catch(() => '');
|
|
260
|
-
throw new DokployCallFailed(
|
|
261
|
-
path,
|
|
262
|
-
response.status,
|
|
263
|
-
response.statusText,
|
|
264
|
-
detail,
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return (await response.json()) as T;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/** Whether an error means the thing is already absent. */
|
|
272
|
-
function isNotFound(error: unknown): boolean {
|
|
273
|
-
return error instanceof DokployCallFailed && error.status === 404;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export interface ApplicationArgs {
|
|
277
|
-
endpoint: Input<string>;
|
|
278
|
-
apiToken: Input<string>;
|
|
279
|
-
name: Input<string>;
|
|
280
|
-
projectId: Input<string>;
|
|
281
|
-
environmentId: Input<string>;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* The provider itself, for tests: its create/read/update/delete are what talk
|
|
286
|
-
* to Dokploy, and a dynamic resource gives no other way to reach them without a
|
|
287
|
-
* Pulumi engine.
|
|
288
|
-
*/
|
|
289
|
-
export { provider as applicationProvider };
|
|
290
|
-
|
|
291
|
-
export class Application extends dynamic.Resource {
|
|
292
|
-
declare readonly applicationId: Output<string>;
|
|
293
|
-
declare readonly appName: Output<string>;
|
|
294
|
-
|
|
295
|
-
constructor(name: string, args: ApplicationArgs, opts?: object) {
|
|
296
|
-
super(
|
|
297
|
-
provider,
|
|
298
|
-
name,
|
|
299
|
-
// The outputs have to be declared as undefined inputs or Pulumi will
|
|
300
|
-
// not populate them — a quiet rule, and the usual first thing to get
|
|
301
|
-
// wrong with a dynamic provider.
|
|
302
|
-
{ ...args, applicationId: undefined, appName: undefined },
|
|
303
|
-
opts,
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
}
|