@appstrate/afps-shared 0.9.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appstrate/afps-shared",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Zero-dependency AFPS helpers shared by @appstrate/core and @appstrate/afps-runtime (companion-file checks, semver resolution, SRI integrity, credential templates, delivery.http projection)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -4,10 +4,7 @@
4
4
  /**
5
5
  * Canonical `{$credential.<field>}` value-template renderer — the SINGLE
6
6
  * source of truth. Consumers import this module directly; core no longer
7
- * publishes a `./credential-template` subpath (removed in core 6.0.0). The
8
- * only importer today is `apps/api/src/services/integration-manifest-helpers.ts`,
9
- * which re-exports it pre-bound to `emptyAs: "null"` for
10
- * `integration-spawn-resolver.ts`.
7
+ * publishes a `./credential-template` subpath (removed in core 6.0.0).
11
8
  *
12
9
  * AFPS `delivery.http` / `delivery.env` / `delivery.files` value templates
13
10
  * reference an auth's decrypted credential bag via the `{$credential.<field>}`
@@ -54,3 +51,30 @@ export function renderCredentialTemplate(
54
51
  if (opts.emptyAs === "null") return rendered.length === 0 ? null : rendered;
55
52
  return rendered;
56
53
  }
54
+
55
+ /** Field names referenced by `{$credential.<name>}` placeholders, in order, deduplicated. */
56
+ export function credentialTemplateRefs(template: string): string[] {
57
+ return [...new Set(Array.from(template.matchAll(CREDENTIAL_REF), (m) => m[1]!))];
58
+ }
59
+
60
+ /** A rendered value may only be a literal host label run or port digits, never dots alone. */
61
+ const AUTHORITY_VALUE = /^(?!\.+$)[A-Za-z0-9.-]+$/;
62
+
63
+ /**
64
+ * Render `authorized_uris` for one connection (#1458). A templated pattern is DROPPED when a
65
+ * referenced field fails {@link AUTHORITY_VALUE}, so a value cannot add a wildcard, a separator
66
+ * or another host. Import validation confines placeholders to the host and port.
67
+ */
68
+ export function renderAuthorizedUris(
69
+ patterns: readonly string[],
70
+ fields: Readonly<Record<string, string>>,
71
+ ): string[] {
72
+ return patterns.flatMap((pattern) => {
73
+ const refs = credentialTemplateRefs(pattern);
74
+ const renderable = refs.every((ref) => {
75
+ const value = fields[ref];
76
+ return typeof value === "string" && AUTHORITY_VALUE.test(value);
77
+ });
78
+ return renderable ? [renderCredentialTemplate(pattern, fields)] : [];
79
+ });
80
+ }