@fraym/projections 0.12.0 → 0.13.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 +23 -0
- package/dist/cmd/projections.js +20 -3
- package/dist/management/getAll.js +3 -0
- package/dist/management/remove.js +4 -1
- package/dist/management/upsert.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,29 @@ PERMISSIONS_SCHEMA_GLOB=
|
|
|
44
44
|
PROJECTIONS_NAMESPACE=
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
## Env variable placeholders in migrations
|
|
48
|
+
|
|
49
|
+
You can use placeholders that match environment variables in argument strings in your schema definitions:
|
|
50
|
+
|
|
51
|
+
In the following example the `{{env.BACKEND_HOSTNAME}}` part will be replaced by the value of the `BACKEND_HOSTNAME` environment variable.
|
|
52
|
+
Please add your used env variables to the `.env` file that is used to [configure the migration command](#config).
|
|
53
|
+
|
|
54
|
+
```graphql
|
|
55
|
+
type TestType {
|
|
56
|
+
value: String
|
|
57
|
+
@webhook(
|
|
58
|
+
url: "http://{{env.BACKEND_HOSTNAME}}/event-organizing/contingent/projections/frontend/contingent-management/webhook"
|
|
59
|
+
method: "GET"
|
|
60
|
+
header: [{ key: "Content-Type", value: "'application/json'" }]
|
|
61
|
+
body: [
|
|
62
|
+
{ key: "metadata", value: "metadata" }
|
|
63
|
+
{ key: "payload", value: "payload" }
|
|
64
|
+
{ key: "projection", value: "projection" }
|
|
65
|
+
]
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
47
70
|
## Usage
|
|
48
71
|
|
|
49
72
|
### Create the clients
|
package/dist/cmd/projections.js
CHANGED
|
@@ -17,7 +17,7 @@ const run = async () => {
|
|
|
17
17
|
.config({
|
|
18
18
|
schemaGlob: "./src/**/*.graphql",
|
|
19
19
|
permissionsSchemaGlob: "",
|
|
20
|
-
serverAddress: "127.0.0.1
|
|
20
|
+
serverAddress: "http://127.0.0.1",
|
|
21
21
|
apiToken: "",
|
|
22
22
|
namespace: "",
|
|
23
23
|
})
|
|
@@ -302,12 +302,12 @@ const migrateSchemas = async (definitions, serverAddress, apiToken, namespace) =
|
|
|
302
302
|
});
|
|
303
303
|
if (projectionsToCreate.length > 0) {
|
|
304
304
|
console.log(`Creating ${projectionsToCreate.length} projections: ${projectionsToCreate}...`);
|
|
305
|
-
await managementClient.upsert(createSchema);
|
|
305
|
+
await managementClient.upsert(replaceWithEnvData(createSchema));
|
|
306
306
|
console.log(`Created ${projectionsToCreate.length} projections`);
|
|
307
307
|
}
|
|
308
308
|
if (projectionsToUpdate.length > 0) {
|
|
309
309
|
console.log(`Updating ${projectionsToUpdate.length} projections: ${projectionsToUpdate}...`);
|
|
310
|
-
await managementClient.upsert(updateSchema);
|
|
310
|
+
await managementClient.upsert(replaceWithEnvData(updateSchema));
|
|
311
311
|
console.log(`Updated ${projectionsToUpdate.length} projections`);
|
|
312
312
|
}
|
|
313
313
|
if (projectionsToRemove.length > 0) {
|
|
@@ -316,6 +316,23 @@ const migrateSchemas = async (definitions, serverAddress, apiToken, namespace) =
|
|
|
316
316
|
console.log(`Removed ${projectionsToRemove.length} projections`);
|
|
317
317
|
}
|
|
318
318
|
};
|
|
319
|
+
const replaceWithEnvData = (str) => {
|
|
320
|
+
const regex = /{{env\.([a-zA-Z_]+)}}/g;
|
|
321
|
+
const matches = str.match(regex);
|
|
322
|
+
const envData = {};
|
|
323
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach(match => {
|
|
324
|
+
var _a;
|
|
325
|
+
const variable = match.replace("{{env.", "").replace("}}", "");
|
|
326
|
+
if (!envData[variable]) {
|
|
327
|
+
envData[variable] = (_a = process.env[variable]) !== null && _a !== void 0 ? _a : "";
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
let outputStr = str;
|
|
331
|
+
Object.keys(envData).forEach(key => {
|
|
332
|
+
outputStr = outputStr.replaceAll(`{{env.${key}}}`, envData[key]);
|
|
333
|
+
});
|
|
334
|
+
return outputStr;
|
|
335
|
+
};
|
|
319
336
|
const ensureValidName = (name) => {
|
|
320
337
|
if (name.startsWith("Fraym")) {
|
|
321
338
|
throw new Error(`Cannot use Fraym as projection name prefix as it is reserved for fraym apps, got ${name}`);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeProjections = void 0;
|
|
4
4
|
const removeProjections = async (projectionNames, config) => {
|
|
5
|
-
await fetch(`${config.serverAddress}/management/projections`, {
|
|
5
|
+
const response = await fetch(`${config.serverAddress}/management/projections`, {
|
|
6
6
|
method: "DELETE",
|
|
7
7
|
headers: {
|
|
8
8
|
Authorization: `Bearer ${config.apiToken}`,
|
|
@@ -12,5 +12,8 @@ const removeProjections = async (projectionNames, config) => {
|
|
|
12
12
|
projectionNames,
|
|
13
13
|
}),
|
|
14
14
|
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(await response.text());
|
|
17
|
+
}
|
|
15
18
|
};
|
|
16
19
|
exports.removeProjections = removeProjections;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.upsertProjections = void 0;
|
|
4
4
|
const upsertProjections = async (schema, config) => {
|
|
5
|
-
await fetch(`${config.serverAddress}/management/projections`, {
|
|
5
|
+
const response = await fetch(`${config.serverAddress}/management/projections`, {
|
|
6
6
|
method: "POST",
|
|
7
7
|
headers: {
|
|
8
8
|
Authorization: `Bearer ${config.apiToken}`,
|
|
@@ -12,5 +12,8 @@ const upsertProjections = async (schema, config) => {
|
|
|
12
12
|
schema,
|
|
13
13
|
}),
|
|
14
14
|
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
throw new Error(await response.text());
|
|
17
|
+
}
|
|
15
18
|
};
|
|
16
19
|
exports.upsertProjections = upsertProjections;
|