@tinycloud/sdk-core 3.8.0-beta.2 → 3.8.0-beta.4

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/dist/index.cjs CHANGED
@@ -7835,6 +7835,14 @@ function expandEncryptionPermissionEntry(entry) {
7835
7835
  `tinycloud.encryption entries require path to be a networkId URN (got ${JSON.stringify(entry.path)})`
7836
7836
  );
7837
7837
  }
7838
+ if (entry.path.includes("/")) {
7839
+ throw new ManifestValidationError("named keys go in manifest.keys");
7840
+ }
7841
+ try {
7842
+ (0, import_sdk_services2.parseNetworkId)(entry.path);
7843
+ } catch {
7844
+ throw new ManifestValidationError("tinycloud.encryption entries require a valid networkId URN");
7845
+ }
7838
7846
  const normalizedActions = [];
7839
7847
  for (const action of entry.actions) {
7840
7848
  if (action === "decrypt" || action === "tinycloud.encryption/decrypt") {
@@ -7959,8 +7967,56 @@ function validateManifest(input) {
7959
7967
  if (m.secrets !== void 0) {
7960
7968
  validateManifestSecrets(m.secrets);
7961
7969
  }
7970
+ if (Object.prototype.hasOwnProperty.call(m, "keys_app_id") && (typeof m.keys_app_id !== "string" || !KEY_APP_ID.test(m.keys_app_id))) {
7971
+ throw new ManifestValidationError("manifest.keys_app_id is invalid");
7972
+ }
7973
+ validateManifestKeys(m.keys_app_id ?? m.app_id, m.keys);
7962
7974
  return m;
7963
7975
  }
7976
+ var KEY_SEGMENT = "[a-z0-9][a-z0-9._-]{0,63}";
7977
+ var KEY_APP_ID = new RegExp(`^${KEY_SEGMENT}$`);
7978
+ var KEY_PATH = new RegExp(`^${KEY_SEGMENT}(?:/${KEY_SEGMENT}){2,7}$`);
7979
+ var KEY_ABILITIES = ["key.create", "decrypt", "key.block", "key.unblock"];
7980
+ function validateManifestKeys(appId, keys) {
7981
+ if (keys === void 0) return;
7982
+ if (!Array.isArray(keys) || keys.length > 32) {
7983
+ throw new ManifestValidationError("manifest.keys must contain at most 32 entries");
7984
+ }
7985
+ if (keys.length === 0) return;
7986
+ if (!KEY_APP_ID.test(appId)) {
7987
+ throw new ManifestValidationError("manifest.keys requires a valid app_id");
7988
+ }
7989
+ const paths = /* @__PURE__ */ new Set();
7990
+ let prefixSeen = false;
7991
+ for (const [index, value] of keys.entries()) {
7992
+ const label = `manifest.keys[${index}]`;
7993
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
7994
+ throw new ManifestValidationError(`${label} must be an object`);
7995
+ }
7996
+ const entry = value;
7997
+ const fields = Object.keys(entry);
7998
+ const hasPath = Object.prototype.hasOwnProperty.call(entry, "path");
7999
+ const hasPrefix = Object.prototype.hasOwnProperty.call(entry, "prefix");
8000
+ if (hasPath === hasPrefix || fields.some((field) => !["path", "prefix", "abilities"].includes(field))) {
8001
+ throw new ManifestValidationError(`${label} must have one path or prefix and abilities`);
8002
+ }
8003
+ if (!Array.isArray(entry.abilities) || entry.abilities.length === 0 || new Set(entry.abilities).size !== entry.abilities.length || entry.abilities.some((ability) => typeof ability !== "string" || !KEY_ABILITIES.includes(ability))) {
8004
+ throw new ManifestValidationError(`${label}.abilities is invalid`);
8005
+ }
8006
+ if (hasPath) {
8007
+ const path = entry.path;
8008
+ if (typeof path !== "string" || path.length > 255 || !KEY_PATH.test(path) || !path.startsWith(`apps/${appId}/`) || paths.has(path)) {
8009
+ throw new ManifestValidationError(`${label}.path is invalid`);
8010
+ }
8011
+ paths.add(path);
8012
+ } else {
8013
+ if (entry.prefix !== `apps/${appId}/` || prefixSeen) {
8014
+ throw new ManifestValidationError(`${label}.prefix is invalid`);
8015
+ }
8016
+ prefixSeen = true;
8017
+ }
8018
+ }
8019
+ }
7964
8020
  function resolveManifestKnowledgeRoot(knowledge) {
7965
8021
  if (knowledge === void 0) {
7966
8022
  return void 0;