@fraym/projections 0.12.1 → 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 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
@@ -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}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/projections",
3
- "version": "0.12.1",
3
+ "version": "0.13.0",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/projections-nodejs",
6
6
  "repository": {