@adobe/aio-lib-db 1.0.0 → 1.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/lib/DbBase.js +5 -1
- package/package.json +1 -1
- package/utils/runtimeNamespace.js +27 -0
package/lib/DbBase.js
CHANGED
|
@@ -19,6 +19,7 @@ const {
|
|
|
19
19
|
ALLOWED_REGIONS, STAGE_ENV, STAGE_ENDPOINT, PROD_ENDPOINT_RUNTIME, PROD_ENDPOINT_EXTERNAL
|
|
20
20
|
} = require("./constants")
|
|
21
21
|
const { getCliEnv } = require("@adobe/aio-lib-env")
|
|
22
|
+
const { isProdWorkspace } = require("../utils/runtimeNamespace")
|
|
22
23
|
|
|
23
24
|
class DbBase {
|
|
24
25
|
/**
|
|
@@ -28,7 +29,6 @@ class DbBase {
|
|
|
28
29
|
* @hideconstructor
|
|
29
30
|
*/
|
|
30
31
|
constructor(region, runtimeNamespace, token) {
|
|
31
|
-
|
|
32
32
|
this.runtimeNamespace = runtimeNamespace
|
|
33
33
|
if (!this.runtimeNamespace) {
|
|
34
34
|
throw new DbError('Runtime namespace is required')
|
|
@@ -46,6 +46,10 @@ class DbBase {
|
|
|
46
46
|
throw new DbError(`Invalid region '${region}' for the ${env} environment, must be one of: ${validRegions.join(', ')}`)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
if (process.env.AIO_DEV && isProdWorkspace(this.runtimeNamespace)) {
|
|
50
|
+
throw new DbError('Cannot access production databases when using \'aio app dev\'.')
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
let serviceUrl
|
|
50
54
|
// Allow overriding service URL via environment variable for testing
|
|
51
55
|
if (process.env.AIO_DB_ENDPOINT) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const prodWorkspaceCheck = new RegExp(`^(development-)?\\d+-[a-z0-9]+$`, 'i')
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the namespace is for a production workspace
|
|
17
|
+
* Production: 123456-testProject / development-123456-testProject
|
|
18
|
+
* Non-production: 123456-testProject-<tag> / development-123456-testProject-<tag>
|
|
19
|
+
*
|
|
20
|
+
* @param {string} runtimeNamespace
|
|
21
|
+
* @return {boolean}
|
|
22
|
+
**/
|
|
23
|
+
function isProdWorkspace(runtimeNamespace) {
|
|
24
|
+
return prodWorkspaceCheck.test(runtimeNamespace)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { isProdWorkspace }
|