@dbos-inc/dbos-cloud 1.0.2 → 1.1.5-preview

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.
Files changed (121) hide show
  1. package/dist/applications/delete-app.d.ts.map +1 -0
  2. package/dist/applications/delete-app.js +34 -0
  3. package/dist/applications/delete-app.js.map +1 -0
  4. package/dist/applications/deploy-app-code.d.ts.map +1 -0
  5. package/dist/{packages/dbos-cloud/applications → applications}/deploy-app-code.js +23 -30
  6. package/dist/applications/deploy-app-code.js.map +1 -0
  7. package/dist/applications/get-app-info.d.ts.map +1 -0
  8. package/dist/applications/get-app-info.js +43 -0
  9. package/dist/applications/get-app-info.js.map +1 -0
  10. package/dist/applications/get-app-logs.d.ts.map +1 -0
  11. package/dist/{packages/dbos-cloud/applications → applications}/get-app-logs.js +9 -16
  12. package/dist/applications/get-app-logs.js.map +1 -0
  13. package/dist/applications/index.d.ts +7 -0
  14. package/dist/applications/index.d.ts.map +1 -0
  15. package/dist/applications/index.js +7 -0
  16. package/dist/applications/index.js.map +1 -0
  17. package/dist/applications/list-apps.d.ts.map +1 -0
  18. package/dist/applications/list-apps.js +41 -0
  19. package/dist/applications/list-apps.js.map +1 -0
  20. package/dist/applications/register-app.d.ts.map +1 -0
  21. package/dist/applications/register-app.js +39 -0
  22. package/dist/applications/register-app.js.map +1 -0
  23. package/dist/applications/types.d.ts.map +1 -0
  24. package/dist/{packages/dbos-cloud/applications → applications}/types.js +1 -5
  25. package/dist/applications/types.js.map +1 -0
  26. package/dist/applications/update-app.d.ts.map +1 -0
  27. package/dist/applications/update-app.js +38 -0
  28. package/dist/applications/update-app.js.map +1 -0
  29. package/dist/cli.d.ts.map +1 -0
  30. package/dist/{packages/dbos-cloud/cli.js → cli.js} +58 -35
  31. package/dist/cli.js.map +1 -0
  32. package/dist/{packages/dbos-cloud/cloudutils.d.ts → cloudutils.d.ts} +1 -1
  33. package/dist/cloudutils.d.ts.map +1 -0
  34. package/dist/cloudutils.js +126 -0
  35. package/dist/cloudutils.js.map +1 -0
  36. package/dist/dashboards.d.ts.map +1 -0
  37. package/{dashboards.ts → dist/dashboards.js} +24 -24
  38. package/dist/dashboards.js.map +1 -0
  39. package/dist/login.d.ts.map +1 -0
  40. package/dist/{packages/dbos-cloud/login.js → login.js} +25 -26
  41. package/dist/login.js.map +1 -0
  42. package/dist/register.d.ts.map +1 -0
  43. package/dist/register.js +86 -0
  44. package/dist/register.js.map +1 -0
  45. package/dist/userdb.d.ts.map +1 -0
  46. package/dist/{packages/dbos-cloud/userdb.js → userdb.js} +34 -47
  47. package/dist/userdb.js.map +1 -0
  48. package/package.json +7 -3
  49. package/Gruntfile.js +0 -9
  50. package/applications/delete-app.ts +0 -35
  51. package/applications/deploy-app-code.ts +0 -126
  52. package/applications/get-app-info.ts +0 -42
  53. package/applications/get-app-logs.ts +0 -45
  54. package/applications/index.ts +0 -7
  55. package/applications/list-apps.ts +0 -42
  56. package/applications/register-app.ts +0 -43
  57. package/applications/types.ts +0 -19
  58. package/applications/update-app.ts +0 -43
  59. package/cli.ts +0 -225
  60. package/cloudutils.ts +0 -166
  61. package/dist/packages/dbos-cloud/applications/delete-app.d.ts.map +0 -1
  62. package/dist/packages/dbos-cloud/applications/delete-app.js +0 -41
  63. package/dist/packages/dbos-cloud/applications/delete-app.js.map +0 -1
  64. package/dist/packages/dbos-cloud/applications/deploy-app-code.d.ts.map +0 -1
  65. package/dist/packages/dbos-cloud/applications/deploy-app-code.js.map +0 -1
  66. package/dist/packages/dbos-cloud/applications/get-app-info.d.ts.map +0 -1
  67. package/dist/packages/dbos-cloud/applications/get-app-info.js +0 -50
  68. package/dist/packages/dbos-cloud/applications/get-app-info.js.map +0 -1
  69. package/dist/packages/dbos-cloud/applications/get-app-logs.d.ts.map +0 -1
  70. package/dist/packages/dbos-cloud/applications/get-app-logs.js.map +0 -1
  71. package/dist/packages/dbos-cloud/applications/index.d.ts +0 -7
  72. package/dist/packages/dbos-cloud/applications/index.d.ts.map +0 -1
  73. package/dist/packages/dbos-cloud/applications/index.js +0 -16
  74. package/dist/packages/dbos-cloud/applications/index.js.map +0 -1
  75. package/dist/packages/dbos-cloud/applications/list-apps.d.ts.map +0 -1
  76. package/dist/packages/dbos-cloud/applications/list-apps.js +0 -48
  77. package/dist/packages/dbos-cloud/applications/list-apps.js.map +0 -1
  78. package/dist/packages/dbos-cloud/applications/register-app.d.ts.map +0 -1
  79. package/dist/packages/dbos-cloud/applications/register-app.js +0 -46
  80. package/dist/packages/dbos-cloud/applications/register-app.js.map +0 -1
  81. package/dist/packages/dbos-cloud/applications/types.d.ts.map +0 -1
  82. package/dist/packages/dbos-cloud/applications/types.js.map +0 -1
  83. package/dist/packages/dbos-cloud/applications/update-app.d.ts.map +0 -1
  84. package/dist/packages/dbos-cloud/applications/update-app.js +0 -45
  85. package/dist/packages/dbos-cloud/applications/update-app.js.map +0 -1
  86. package/dist/packages/dbos-cloud/cli.d.ts.map +0 -1
  87. package/dist/packages/dbos-cloud/cli.js.map +0 -1
  88. package/dist/packages/dbos-cloud/cloudutils.d.ts.map +0 -1
  89. package/dist/packages/dbos-cloud/cloudutils.js +0 -145
  90. package/dist/packages/dbos-cloud/cloudutils.js.map +0 -1
  91. package/dist/packages/dbos-cloud/dashboards.d.ts.map +0 -1
  92. package/dist/packages/dbos-cloud/dashboards.js +0 -63
  93. package/dist/packages/dbos-cloud/dashboards.js.map +0 -1
  94. package/dist/packages/dbos-cloud/login.d.ts.map +0 -1
  95. package/dist/packages/dbos-cloud/login.js.map +0 -1
  96. package/dist/packages/dbos-cloud/register.d.ts.map +0 -1
  97. package/dist/packages/dbos-cloud/register.js +0 -116
  98. package/dist/packages/dbos-cloud/register.js.map +0 -1
  99. package/dist/packages/dbos-cloud/userdb.d.ts.map +0 -1
  100. package/dist/packages/dbos-cloud/userdb.js.map +0 -1
  101. package/dist/src/utils.d.ts +0 -6
  102. package/dist/src/utils.d.ts.map +0 -1
  103. package/dist/src/utils.js +0 -51
  104. package/dist/src/utils.js.map +0 -1
  105. package/login.ts +0 -146
  106. package/register.ts +0 -89
  107. package/tsconfig.json +0 -22
  108. package/userdb.ts +0 -191
  109. /package/dist/{packages/dbos-cloud/applications → applications}/delete-app.d.ts +0 -0
  110. /package/dist/{packages/dbos-cloud/applications → applications}/deploy-app-code.d.ts +0 -0
  111. /package/dist/{packages/dbos-cloud/applications → applications}/get-app-info.d.ts +0 -0
  112. /package/dist/{packages/dbos-cloud/applications → applications}/get-app-logs.d.ts +0 -0
  113. /package/dist/{packages/dbos-cloud/applications → applications}/list-apps.d.ts +0 -0
  114. /package/dist/{packages/dbos-cloud/applications → applications}/register-app.d.ts +0 -0
  115. /package/dist/{packages/dbos-cloud/applications → applications}/types.d.ts +0 -0
  116. /package/dist/{packages/dbos-cloud/applications → applications}/update-app.d.ts +0 -0
  117. /package/dist/{packages/dbos-cloud/cli.d.ts → cli.d.ts} +0 -0
  118. /package/dist/{packages/dbos-cloud/dashboards.d.ts → dashboards.d.ts} +0 -0
  119. /package/dist/{packages/dbos-cloud/login.d.ts → login.d.ts} +0 -0
  120. /package/dist/{packages/dbos-cloud/register.d.ts → register.d.ts} +0 -0
  121. /package/dist/{packages/dbos-cloud/userdb.d.ts → userdb.d.ts} +0 -0
package/dist/src/utils.js DELETED
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findPackageRoot = exports.sleep = exports.readFileSync = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- /*
10
- * Use the node.js `fs` module to read the content of a file
11
- * Handles cases where:
12
- * - the file does not exist
13
- * - the file is not a valid file
14
- **/
15
- function readFileSync(path, encoding = "utf8") {
16
- // First, check the file
17
- fs_1.default.stat(path, (error, stats) => {
18
- if (error) {
19
- throw new Error(`checking on ${path}. ${error.code}: ${error.errno}`);
20
- }
21
- else if (!stats.isFile()) {
22
- throw new Error(`config file ${path} is not a file`);
23
- }
24
- });
25
- // Then, read its content
26
- const fileContent = fs_1.default.readFileSync(path, { encoding });
27
- return fileContent;
28
- }
29
- exports.readFileSync = readFileSync;
30
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
31
- exports.sleep = sleep;
32
- // Adapated and translated from from: https://github.com/junosuarez/find-root
33
- function findPackageRoot(start) {
34
- if (typeof start === 'string') {
35
- if (!start.endsWith(path_1.default.sep)) {
36
- start += path_1.default.sep;
37
- }
38
- start = start.split(path_1.default.sep);
39
- }
40
- if (start.length === 0) {
41
- throw new Error('package.json not found in path');
42
- }
43
- start.pop();
44
- const dir = start.join(path_1.default.sep);
45
- if (fs_1.default.existsSync(path_1.default.join(dir, 'package.json'))) {
46
- return dir;
47
- }
48
- return findPackageRoot(start);
49
- }
50
- exports.findPackageRoot = findPackageRoot;
51
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB;;;;;IAKI;AACJ,SAAgB,YAAY,CAAC,IAAY,EAAE,WAA2B,MAAM;IAC1E,wBAAwB;IACxB,YAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAmC,EAAE,KAAe,EAAE,EAAE;QACrE,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QACxE,CAAC;aAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,gBAAgB,CAAC,CAAC;QACvD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,yBAAyB;IACzB,MAAM,WAAW,GAAW,YAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAE,CAAC;IACjE,OAAO,WAAW,CAAC;AACrB,CAAC;AAbD,oCAaC;AAEM,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAA9D,QAAA,KAAK,SAAyD;AAI3E,6EAA6E;AAC7E,SAAgB,eAAe,CAAC,KAAwB;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,KAAK,IAAI,cAAI,CAAC,GAAG,CAAC;QACtB,CAAC;QACD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,cAAI,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,GAAG,EAAE,CAAC;IACZ,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,cAAI,CAAC,GAAG,CAAC,CAAC;IAEjC,IAAI,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QAChD,OAAO,GAAG,CAAC;IACf,CAAC;IAED,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AApBD,0CAoBC"}
package/login.ts DELETED
@@ -1,146 +0,0 @@
1
- import axios, { AxiosError } from "axios";
2
- import jwt, { JwtPayload } from 'jsonwebtoken';
3
- import jwksClient from 'jwks-rsa';
4
- import { DBOSCloudCredentials, getLogger, handleAPIErrors, isCloudAPIErrorResponse, sleep, writeCredentials } from "./cloudutils";
5
- import { Logger } from "winston";
6
-
7
- const DBOSCloudHost = process.env.DBOS_DOMAIN || "cloud.dbos.dev";
8
- const productionEnvironment = DBOSCloudHost === "cloud.dbos.dev";
9
- const Auth0Domain = productionEnvironment ? 'login.dbos.dev' : 'dbos-inc.us.auth0.com';
10
- const DBOSClientID = productionEnvironment ? '6p7Sjxf13cyLMkdwn14MxlH7JdhILled' : 'G38fLmVErczEo9ioCFjVIHea6yd0qMZu';
11
- const DBOSCloudIdentifier = 'dbos-cloud-api';
12
-
13
- interface DeviceCodeResponse {
14
- device_code: string;
15
- user_code: string;
16
- verification_uri: string;
17
- verification_uri_complete: string;
18
- expires_in: number;
19
- interval: number;
20
- }
21
-
22
- interface TokenResponse {
23
- access_token: string;
24
- token_type: string;
25
- expires_in: number;
26
- }
27
-
28
- const client = jwksClient({
29
- jwksUri: `https://${Auth0Domain}/.well-known/jwks.json`
30
- });
31
-
32
- async function getSigningKey(kid: string): Promise<string> {
33
- const key = await client.getSigningKey(kid);
34
- return key.getPublicKey();
35
- }
36
-
37
- async function verifyToken(token: string): Promise<JwtPayload> {
38
- const decoded = jwt.decode(token, { complete: true });
39
-
40
- if (!decoded || typeof decoded === 'string' || !decoded.header.kid) {
41
- throw new Error('Invalid token');
42
- }
43
-
44
- const signingKey = await getSigningKey(decoded.header.kid);
45
-
46
- return new Promise((resolve, reject) => {
47
- jwt.verify(token, signingKey, { algorithms: ['RS256'] }, (err, verifiedToken) => {
48
- if (err) {
49
- reject(err);
50
- } else {
51
- resolve(verifiedToken as JwtPayload);
52
- }
53
- });
54
- });
55
- }
56
-
57
- // Redirect a user to auth0 to authenticate, retrieving a JWT bearer token
58
- export async function authenticate(logger: Logger): Promise<string | null> {
59
- logger.info(`Please authenticate with DBOS Cloud!`);
60
-
61
- const deviceCodeRequest = {
62
- method: 'POST',
63
- url: `https://${Auth0Domain}/oauth/device/code`,
64
- headers: { 'content-type': 'application/x-www-form-urlencoded' },
65
- data: { client_id: DBOSClientID, scope: 'sub', audience: DBOSCloudIdentifier }
66
- };
67
- let deviceCodeResponse: DeviceCodeResponse | undefined;
68
- try {
69
- const response = await axios.request(deviceCodeRequest);
70
- deviceCodeResponse = response.data as DeviceCodeResponse;
71
- } catch (e) {
72
- (e as Error).message = `failed to log in: ${(e as Error).message}`;
73
- logger.error(e);
74
- }
75
- if (!deviceCodeResponse) {
76
- return null;
77
- }
78
- console.log(`Login URL: ${deviceCodeResponse.verification_uri_complete}`);
79
-
80
- const tokenRequest = {
81
- method: 'POST',
82
- url: `https://${Auth0Domain}/oauth/token`,
83
- headers: { 'content-type': 'application/x-www-form-urlencoded' },
84
- data: new URLSearchParams({
85
- grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
86
- device_code: deviceCodeResponse.device_code,
87
- client_id: DBOSClientID
88
- })
89
- };
90
- let tokenResponse: TokenResponse | undefined;
91
- let elapsedTimeSec = 0;
92
- while (elapsedTimeSec < deviceCodeResponse.expires_in) {
93
- try {
94
- await sleep(deviceCodeResponse.interval * 1000)
95
- elapsedTimeSec += deviceCodeResponse.interval;
96
- const response = await axios.request(tokenRequest);
97
- tokenResponse = response.data as TokenResponse;
98
- break;
99
- } catch (e) {
100
- logger.info(`Waiting for login...`);
101
- }
102
- }
103
- if (!tokenResponse) {
104
- return null;
105
- }
106
-
107
- await verifyToken(tokenResponse.access_token);
108
- return tokenResponse.access_token
109
- }
110
-
111
- export async function login(host: string): Promise<number> {
112
- const logger = getLogger();
113
- const token = await authenticate(logger)
114
- if (token === null) {
115
- return 1;
116
- }
117
- const bearerToken = "Bearer " + token;
118
- try {
119
- const response = await axios.get(
120
- `https://${host}/v1alpha1/user`,
121
- {
122
- headers: {
123
- "Content-Type": "application/json",
124
- Authorization: bearerToken,
125
- },
126
- }
127
- );
128
- const username = response.data as string;
129
- const credentials: DBOSCloudCredentials = {
130
- token: token,
131
- userName: username,
132
- };
133
- writeCredentials(credentials)
134
- logger.info(`Successfully logged in as ${credentials.userName}!`);
135
- } catch (e) {
136
- const errorLabel = `Failed to login`;
137
- const axiosError = e as AxiosError;
138
- if (isCloudAPIErrorResponse(axiosError.response?.data)) {
139
- handleAPIErrors(errorLabel, axiosError);
140
- } else {
141
- logger.error(`${errorLabel}: ${(e as Error).message}`);
142
- }
143
- return 1;
144
- }
145
- return 0;
146
- }
package/register.ts DELETED
@@ -1,89 +0,0 @@
1
- import axios, { AxiosError } from "axios";
2
- import { handleAPIErrors, getCloudCredentials, getLogger, isCloudAPIErrorResponse, credentialsExist, DBOSCloudCredentials, writeCredentials, deleteCredentials } from "./cloudutils";
3
- import readline from 'readline';
4
- import { authenticate } from "./login";
5
- import * as validator from 'validator';
6
-
7
- const rl = readline.createInterface({
8
- input: process.stdin,
9
- output: process.stdout
10
- });
11
-
12
- function isValidUsername(username: string): boolean {
13
- if (username.length < 3 || username.length > 30) {
14
- return false;
15
- }
16
- return validator.matches(username, "^[a-z0-9_]+$");
17
- }
18
-
19
- export async function registerUser(username: string, host: string): Promise<number> {
20
- const logger = getLogger();
21
- let givenName = "";
22
- let familyName = "";
23
- let company = "";
24
- if (!isValidUsername(username)) {
25
- logger.error("Invalid username. Usernames must be between 3 and 30 characters long and contain only lowercase letters, underscores, and numbers.")
26
- return 1
27
- }
28
- if (!credentialsExist()) {
29
- logger.info("Welcome to DBOS Cloud!")
30
- logger.info("Before creating an account, please tell us a bit about yourself!")
31
- const prompt = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve));
32
- givenName = await prompt("Enter First/Given Name: ");
33
- familyName = await prompt("Enter Last/Family Name: ");
34
- company = await prompt("Enter Company: ");
35
- const bearerToken = await authenticate(logger);
36
- if (bearerToken === null) {
37
- return 1
38
- }
39
- const credentials: DBOSCloudCredentials = {
40
- token: bearerToken,
41
- userName: username,
42
- };
43
- writeCredentials(credentials)
44
- } else {
45
- const userCredentials = getCloudCredentials();
46
- if (userCredentials.userName !== username) {
47
- logger.error(`You are trying to register ${username}, but are currently authenticated as ${userCredentials.userName}. Please run "npx dbos-cloud logout".`)
48
- return 1;
49
- } else {
50
- logger.info(`You are currently authenticated as ${userCredentials.userName}. Registering ${userCredentials.userName} with DBOS Cloud...`)
51
- }
52
- }
53
-
54
- const userCredentials = getCloudCredentials();
55
- const bearerToken = "Bearer " + userCredentials.token;
56
- const loginName = userCredentials.userName;
57
- try {
58
- // Register the user in DBOS Cloud
59
- await axios.put(
60
- `https://${host}/v1alpha1/user`,
61
- {
62
- name: loginName,
63
- given_name: givenName,
64
- family_name: familyName,
65
- company: company,
66
- },
67
- {
68
- headers: {
69
- "Content-Type": "application/json",
70
- Authorization: bearerToken,
71
- },
72
- }
73
- );
74
- logger.info(`${username} successfully registered!`);
75
- } catch (e) {
76
- const errorLabel = `Failed to register user ${loginName}`;
77
- const axiosError = e as AxiosError;
78
- if (isCloudAPIErrorResponse(axiosError.response?.data)) {
79
- handleAPIErrors(errorLabel, axiosError);
80
- } else {
81
- logger.error(`${errorLabel}: ${(e as Error).message}`);
82
- }
83
- if (credentialsExist()) {
84
- deleteCredentials();
85
- }
86
- return 1;
87
- }
88
- return 0;
89
- }
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- /* Visit https://aka.ms/tsconfig to read more about this file */
2
- {
3
- "compilerOptions": {
4
- "target": "esnext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
5
- "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
6
- "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
7
- "module": "commonjs", /* Specify what module code is generated. */
8
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
9
- "declarationMap": true, /* Create sourcemaps for d.ts files. */
10
- "sourceMap": true, /* Create source map files for emitted JavaScript files. */
11
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
12
- "newLine": "lf", /* Set the newline character for emitting files. */
13
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
14
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
15
- "strict": true, /* Enable all strict type-checking options. */
16
- "skipLibCheck": true, /* Skip type checking all .d.ts files. */
17
- },
18
- "include": [ /* Specifies an array of filenames or patterns to include in the program. */
19
- ".",
20
- "applications"
21
- ],
22
- }
package/userdb.ts DELETED
@@ -1,191 +0,0 @@
1
- import axios, { AxiosError } from "axios";
2
- import { isCloudAPIErrorResponse, handleAPIErrors, getCloudCredentials, getLogger } from "./cloudutils";
3
- import { sleep } from "../../src/utils";
4
-
5
- export interface UserDBInstance {
6
- readonly PostgresInstanceName: string;
7
- readonly Status: string;
8
- readonly HostName: string;
9
- readonly Port: number;
10
- readonly AdminUsername: string; /* TODO: Remove */
11
- readonly DatabaseUsername: string;
12
- }
13
-
14
- export async function createUserDb(host: string, dbName: string, appDBUsername: string, appDBPassword: string, sync: boolean) {
15
- const logger = getLogger();
16
- const userCredentials = getCloudCredentials();
17
- const bearerToken = "Bearer " + userCredentials.token;
18
-
19
- try {
20
- await axios.post(
21
- `https://${host}/v1alpha1/${userCredentials.userName}/databases/userdb`,
22
- { Name: dbName, AdminName: appDBUsername, AdminPassword: appDBPassword },
23
- {
24
- headers: {
25
- "Content-Type": "application/json",
26
- Authorization: bearerToken,
27
- },
28
- }
29
- );
30
-
31
- logger.info(`Successfully started provisioning database: ${dbName}`);
32
-
33
- if (sync) {
34
- let status = "";
35
- while (status != "available" && status != "backing-up") {
36
- await sleep(30000);
37
- const userDBInfo = await getUserDBInfo(host, dbName);
38
- logger.info(userDBInfo);
39
- status = userDBInfo.Status;
40
- }
41
- }
42
- logger.info(`Database successfully provisioned!`)
43
- return 0;
44
- } catch (e) {
45
- const errorLabel = `Failed to create database ${dbName}`;
46
- const axiosError = e as AxiosError;
47
- if (isCloudAPIErrorResponse(axiosError.response?.data)) {
48
- handleAPIErrors(errorLabel, axiosError);
49
- } else {
50
- logger.error(`${errorLabel}: ${(e as Error).message}`);
51
- }
52
- return 1;
53
- }
54
- }
55
-
56
- export async function deleteUserDb(host: string, dbName: string) {
57
- const logger = getLogger();
58
- const userCredentials = getCloudCredentials();
59
- const bearerToken = "Bearer " + userCredentials.token;
60
-
61
- try {
62
- await axios.delete(`https://${host}/v1alpha1/${userCredentials.userName}/databases/userdb/${dbName}`, {
63
- headers: {
64
- "Content-Type": "application/json",
65
- Authorization: bearerToken,
66
- },
67
- });
68
- logger.info(`Database deleted: ${dbName}`);
69
- return 0;
70
- } catch (e) {
71
- const errorLabel = `Failed to delete database ${dbName}`;
72
- const axiosError = e as AxiosError;
73
- if (isCloudAPIErrorResponse(axiosError.response?.data)) {
74
- handleAPIErrors(errorLabel, axiosError);
75
- } else {
76
- logger.error(`${errorLabel}: ${(e as Error).message}`);
77
- }
78
- return 1;
79
- }
80
- }
81
-
82
- export async function getUserDb(host: string, dbName: string, json: boolean) {
83
- const logger = getLogger();
84
-
85
- try {
86
- const userDBInfo = await getUserDBInfo(host, dbName);
87
- if (json) {
88
- console.log(JSON.stringify(userDBInfo));
89
- } else {
90
- console.log(`Postgres Instance Name: ${userDBInfo.PostgresInstanceName}`);
91
- console.log(`Status: ${userDBInfo.Status}`);
92
- console.log(`Host Name: ${userDBInfo.HostName}`);
93
- console.log(`Port: ${userDBInfo.Port}`);
94
- console.log(`Database Username: ${userDBInfo.AdminUsername}`); /* TODO: DatabaseUsername */
95
- }
96
- return 0;
97
- } catch (e) {
98
- const errorLabel = `Failed to retrieve database record ${dbName}`;
99
- const axiosError = e as AxiosError;
100
- if (isCloudAPIErrorResponse(axiosError.response?.data)) {
101
- handleAPIErrors(errorLabel, axiosError);
102
- } else {
103
- logger.error(`${errorLabel}: ${(e as Error).message}`);
104
- }
105
- return 1;
106
- }
107
- }
108
-
109
- export async function listUserDB(host: string, json: boolean) {
110
- const logger = getLogger();
111
-
112
- try {
113
- const userCredentials = getCloudCredentials();
114
- const bearerToken = "Bearer " + userCredentials.token;
115
-
116
- const res = await axios.get(`https://${host}/v1alpha1/${userCredentials.userName}/databases`, {
117
- headers: {
118
- "Content-Type": "application/json",
119
- Authorization: bearerToken,
120
- },
121
- });
122
-
123
- const userDBs = res.data as UserDBInstance[];
124
- if (json) {
125
- console.log(JSON.stringify(userDBs));
126
- } else {
127
- if (userDBs.length === 0) {
128
- logger.info("No database instances found");
129
- }
130
- userDBs.forEach(userDBInfo => {
131
- console.log(`Postgres Instance Name: ${userDBInfo.PostgresInstanceName}`);
132
- console.log(`Status: ${userDBInfo.Status}`);
133
- console.log(`Host Name: ${userDBInfo.HostName}`);
134
- console.log(`Port: ${userDBInfo.Port}`);
135
- console.log(`Database Username: ${userDBInfo.AdminUsername}`); /* TODO: DatabaseUsername */
136
- });
137
- }
138
- return 0;
139
- } catch (e) {
140
- const errorLabel = `Failed to retrieve info`;
141
- const axiosError = e as AxiosError;
142
- if (isCloudAPIErrorResponse(axiosError.response?.data)) {
143
- handleAPIErrors(errorLabel, axiosError);
144
- } else {
145
- logger.error(`${errorLabel}: ${(e as Error).message}`);
146
- }
147
- return 1;
148
- }
149
- }
150
-
151
- export async function getUserDBInfo(host: string, dbName: string): Promise<UserDBInstance> {
152
- const userCredentials = getCloudCredentials();
153
- const bearerToken = "Bearer " + userCredentials.token;
154
-
155
- const res = await axios.get(`https://${host}/v1alpha1/${userCredentials.userName}/databases/userdb/info/${dbName}`, {
156
- headers: {
157
- "Content-Type": "application/json",
158
- Authorization: bearerToken,
159
- },
160
- });
161
-
162
- return res.data as UserDBInstance;
163
- }
164
-
165
- export async function resetDBCredentials(host: string, dbName: string, appDBPassword: string) {
166
- const logger = getLogger();
167
- const userCredentials = getCloudCredentials();
168
- const bearerToken = "Bearer " + userCredentials.token;
169
-
170
- try {
171
- await axios.post(`https://${host}/v1alpha1/${userCredentials.userName}/databases/userdb/${dbName}/credentials`,
172
- { Name: dbName, Password: appDBPassword },
173
- {
174
- headers: {
175
- "Content-Type": "application/json",
176
- Authorization: bearerToken,
177
- },
178
- });
179
- logger.info(`Successfully reset user password for database: ${dbName}`);
180
- return 0;
181
- } catch (e) {
182
- const errorLabel = `Failed to reset user password for database ${dbName}`;
183
- const axiosError = e as AxiosError;
184
- if (isCloudAPIErrorResponse(axiosError.response?.data)) {
185
- handleAPIErrors(errorLabel, axiosError);
186
- } else {
187
- logger.error(`${errorLabel}: ${(e as Error).message}`);
188
- }
189
- return 1;
190
- }
191
- }
File without changes