@distilled.cloud/mongodb-atlas 0.17.0 → 0.18.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/lib/credentials.d.ts +1 -1
- package/lib/credentials.d.ts.map +1 -1
- package/lib/credentials.js +12 -9
- package/lib/credentials.js.map +1 -1
- package/package.json +2 -2
- package/src/credentials.ts +21 -12
package/lib/credentials.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
1
2
|
import * as Layer from "effect/Layer";
|
|
2
3
|
import * as Redacted from "effect/Redacted";
|
|
3
|
-
import * as Context from "effect/Context";
|
|
4
4
|
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
5
5
|
export declare const DEFAULT_API_BASE_URL = "https://cloud.mongodb.com";
|
|
6
6
|
export interface Config {
|
package/lib/credentials.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,eAAO,MAAM,oBAAoB,8BAA8B,CAAC;AAEhE,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;;AAED,qBAAa,WAAY,SAAQ,gBAEhC;CAAG;AAUJ,eAAO,MAAM,kBAAkB,oFA4C9B,CAAC"}
|
package/lib/credentials.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
+
import * as EffectConfig from "effect/Config";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
1
3
|
import * as Effect from "effect/Effect";
|
|
2
4
|
import * as Layer from "effect/Layer";
|
|
3
5
|
import * as Redacted from "effect/Redacted";
|
|
4
|
-
import * as Context from "effect/Context";
|
|
5
6
|
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
6
7
|
export const DEFAULT_API_BASE_URL = "https://cloud.mongodb.com";
|
|
7
8
|
export class Credentials extends Context.Service()("Mongodb-atlasCredentials") {
|
|
8
9
|
}
|
|
10
|
+
const envConfig = EffectConfig.all({
|
|
11
|
+
clientId: EffectConfig.string("MONGODB_ATLAS_CLIENT_ID"),
|
|
12
|
+
clientSecret: EffectConfig.string("MONGODB_ATLAS_CLIENT_SECRET"),
|
|
13
|
+
apiBaseUrl: EffectConfig.string("MONGODB_ATLAS_API_BASE_URL").pipe(EffectConfig.withDefault(DEFAULT_API_BASE_URL)),
|
|
14
|
+
});
|
|
9
15
|
export const CredentialsFromEnv = Layer.effect(Credentials, Effect.gen(function* () {
|
|
10
|
-
const clientId =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
message: "MONGODB_ATLAS_CLIENT_ID and MONGODB_ATLAS_CLIENT_SECRET environment variables are required",
|
|
16
|
-
});
|
|
17
|
-
}
|
|
16
|
+
const { clientId, clientSecret, apiBaseUrl } = yield* envConfig
|
|
17
|
+
.asEffect()
|
|
18
|
+
.pipe(Effect.mapError(() => new ConfigError({
|
|
19
|
+
message: "MONGODB_ATLAS_CLIENT_ID and MONGODB_ATLAS_CLIENT_SECRET environment variables are required",
|
|
20
|
+
})));
|
|
18
21
|
// Exchange service account credentials for OAuth2 access token
|
|
19
22
|
const res = yield* Effect.tryPromise(() => fetch(`${apiBaseUrl}/api/oauth/token`, {
|
|
20
23
|
method: "POST",
|
package/lib/credentials.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AAOhE,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,OAAO,EAAuB,CACrE,0BAA0B,CAC3B;CAAG;AAEJ,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC;IACjC,QAAQ,EAAE,YAAY,CAAC,MAAM,CAAC,yBAAyB,CAAC;IACxD,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC,6BAA6B,CAAC;IAChE,UAAU,EAAE,YAAY,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,IAAI,CAChE,YAAY,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAC/C;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,MAAM,CAC5C,WAAW,EACX,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,CAAC,SAAS;SAC5D,QAAQ,EAAE;SACV,IAAI,CACH,MAAM,CAAC,QAAQ,CACb,GAAG,EAAE,CACH,IAAI,WAAW,CAAC;QACd,OAAO,EACL,4FAA4F;KAC/F,CAAC,CACL,CACF,CAAC;IAEJ,+DAA+D;IAC/D,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CACxC,KAAK,CAAC,GAAG,UAAU,kBAAkB,EAAE;QACrC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,mCAAmC;YACnD,aAAa,EAAE,SAAS,IAAI,CAAC,GAAG,QAAQ,IAAI,YAAY,EAAE,CAAC,EAAE;SAC9D;QACD,IAAI,EAAE,+BAA+B;KACtC,CAAC,CACH,CAAC;IAEF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACxD,OAAO,KAAK,CAAC,CAAC,IAAI,WAAW,CAAC;YAC5B,OAAO,EAAE,iCAAiC,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE;SAC/D,CAAC,CAAC;IACL,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAGvD,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;QAC7C,UAAU;KACX,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@distilled.cloud/mongodb-atlas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/alchemy-run/distilled",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"specs:update": "git -C specs/distilled-spec-mongodb-atlas fetch && git -C specs/distilled-spec-mongodb-atlas checkout main && git -C specs/distilled-spec-mongodb-atlas pull"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@distilled.cloud/core": "0.
|
|
77
|
+
"@distilled.cloud/core": "0.18.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/bun": "^1.3.0",
|
package/src/credentials.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import * as EffectConfig from "effect/Config";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
1
3
|
import * as Effect from "effect/Effect";
|
|
2
4
|
import * as Layer from "effect/Layer";
|
|
3
5
|
import * as Redacted from "effect/Redacted";
|
|
4
|
-
import * as Context from "effect/Context";
|
|
5
6
|
import { ConfigError } from "@distilled.cloud/core/errors";
|
|
6
7
|
|
|
7
8
|
export const DEFAULT_API_BASE_URL = "https://cloud.mongodb.com";
|
|
@@ -15,20 +16,28 @@ export class Credentials extends Context.Service<Credentials, Config>()(
|
|
|
15
16
|
"Mongodb-atlasCredentials",
|
|
16
17
|
) {}
|
|
17
18
|
|
|
19
|
+
const envConfig = EffectConfig.all({
|
|
20
|
+
clientId: EffectConfig.string("MONGODB_ATLAS_CLIENT_ID"),
|
|
21
|
+
clientSecret: EffectConfig.string("MONGODB_ATLAS_CLIENT_SECRET"),
|
|
22
|
+
apiBaseUrl: EffectConfig.string("MONGODB_ATLAS_API_BASE_URL").pipe(
|
|
23
|
+
EffectConfig.withDefault(DEFAULT_API_BASE_URL),
|
|
24
|
+
),
|
|
25
|
+
});
|
|
26
|
+
|
|
18
27
|
export const CredentialsFromEnv = Layer.effect(
|
|
19
28
|
Credentials,
|
|
20
29
|
Effect.gen(function* () {
|
|
21
|
-
const clientId =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const { clientId, clientSecret, apiBaseUrl } = yield* envConfig
|
|
31
|
+
.asEffect()
|
|
32
|
+
.pipe(
|
|
33
|
+
Effect.mapError(
|
|
34
|
+
() =>
|
|
35
|
+
new ConfigError({
|
|
36
|
+
message:
|
|
37
|
+
"MONGODB_ATLAS_CLIENT_ID and MONGODB_ATLAS_CLIENT_SECRET environment variables are required",
|
|
38
|
+
}),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
32
41
|
|
|
33
42
|
// Exchange service account credentials for OAuth2 access token
|
|
34
43
|
const res = yield* Effect.tryPromise(() =>
|