@mdbase-dev/connect-dev 0.1.0-beta.27 → 0.1.0-beta.29

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
@@ -30,6 +30,17 @@ mdbase-connect-dev validate-manifest public/.well-known/mdbase-app.json --allow-
30
30
  mdbase-connect-dev validate-contract worklog-contract.json
31
31
  ```
32
32
 
33
+ Manifest validation uses the same canonical JSON Schema, semantic checks,
34
+ embedded-resource digest verification, and declaration-size bound as the
35
+ matching Connect server. Run it against the generated artifact in application
36
+ CI—not only against a handwritten source object. Failures include the exact
37
+ JSON-pointer path and rule.
38
+
39
+ Deployed applications can also submit `{ "manifest": ... }` to
40
+ `POST /v1/apps/validate`. That endpoint performs the same validation without
41
+ creating or updating an application registration, making it suitable for
42
+ release smoke tests.
43
+
33
44
  Bundled application declarations support connector-controlled type-pack
34
45
  provisioning. Put the contract, its implementing types, and any referenced
35
46
  schemas in one `provisions.type_packs` transaction. Each manifest entry pins
package/dist/index.d.ts CHANGED
@@ -1,23 +1,11 @@
1
1
  import { MdbaseCollectionClient, type MdbaseCollectionTransport } from "@mdbase-dev/connect";
2
2
  import type { CollectionDescription, CollectionOperation, JsonObject, TypePackProvision } from "@mdbase-dev/connect-protocol";
3
- export interface ValidationIssue {
4
- path: string;
5
- keyword: string;
6
- message: string;
7
- params: Record<string, unknown>;
8
- }
9
- export type ValidationResult = {
10
- valid: true;
11
- issues: [];
12
- } | {
13
- valid: false;
14
- issues: ValidationIssue[];
15
- };
16
- export interface ManifestValidationOptions {
17
- /** Allow HTTP only for localhost/loopback developer manifests. */
18
- allowLocal?: boolean;
19
- }
20
- export declare function validateAppManifest(value: unknown, options?: ManifestValidationOptions): ValidationResult;
3
+ import { formatManifestValidationIssues, validateAppManifest, type ManifestValidationIssue, type ManifestValidationOptions, type ManifestValidationResult } from "@mdbase-dev/connect-protocol/manifest";
4
+ export type ValidationIssue = ManifestValidationIssue;
5
+ export type ValidationResult = ManifestValidationResult;
6
+ export type { ManifestValidationOptions };
7
+ export { validateAppManifest };
8
+ export declare const formatValidationIssues: typeof formatManifestValidationIssues;
21
9
  export declare function validateDataContract(value: unknown): ValidationResult;
22
10
  export declare function validateProtocolValue(value: unknown, definition?: string): ValidationResult;
23
11
  export interface DataContractDocument extends JsonObject {
@@ -117,4 +105,3 @@ export declare class SandboxTransport<Frontmatter extends JsonObject = JsonObjec
117
105
  private recordResult;
118
106
  private append;
119
107
  }
120
- export declare function formatValidationIssues(issues: ValidationIssue[]): string;
package/dist/index.js CHANGED
@@ -2,12 +2,13 @@ import { createHash } from "node:crypto";
2
2
  import { Ajv2020 } from "ajv/dist/2020.js";
3
3
  import { parseDocument } from "yaml";
4
4
  import { MdbaseCollectionClient, connectError } from "@mdbase-dev/connect";
5
- import { isNativeRedirectUri } from "@mdbase-dev/connect-protocol";
6
- import appManifestSchema from "@mdbase-dev/connect-protocol/schemas/mdbase-app.schema.json" with { type: "json" };
5
+ import { formatManifestValidationIssues, validateAppManifest } from "@mdbase-dev/connect-protocol/manifest";
7
6
  import connectProblemSchema from "@mdbase-dev/connect-protocol/schemas/connect-problem.v1.schema.json" with { type: "json" };
8
7
  import dataContractSchema from "@mdbase-dev/connect-protocol/schemas/data-contract.schema.json" with { type: "json" };
9
8
  import connectProtocolSchema from "@mdbase-dev/connect-protocol/schemas/connect-protocol.v1.schema.json" with { type: "json" };
10
9
  import filesSchema from "@mdbase-dev/connect-protocol/schemas/files.v1.schema.json" with { type: "json" };
10
+ export { validateAppManifest };
11
+ export const formatValidationIssues = formatManifestValidationIssues;
11
12
  const ajv = new Ajv2020({
12
13
  allErrors: true,
13
14
  strict: true,
@@ -15,23 +16,11 @@ const ajv = new Ajv2020({
15
16
  strictRequired: false,
16
17
  formats: { "date-time": true, uri: true, uuid: true }
17
18
  });
18
- ajv.addSchema(appManifestSchema);
19
19
  ajv.addSchema(connectProblemSchema);
20
20
  ajv.addSchema(dataContractSchema);
21
21
  ajv.addSchema(filesSchema);
22
22
  ajv.addSchema(connectProtocolSchema);
23
- const appManifestValidator = requiredValidator(String(appManifestSchema.$id));
24
23
  const contractValidator = requiredValidator(String(dataContractSchema.$id));
25
- export function validateAppManifest(value, options = {}) {
26
- const candidate = options.allowLocal ? localManifestSchemaCandidate(value) : value;
27
- const schemaResult = validationResult(appManifestValidator, candidate);
28
- if (!schemaResult.valid)
29
- return schemaResult;
30
- const originResult = validateManifestOrigins(value, options.allowLocal === true);
31
- if (!originResult.valid)
32
- return originResult;
33
- return validateProvisionRequirements(value);
34
- }
35
24
  export function validateDataContract(value) {
36
25
  return validationResult(contractValidator, value);
37
26
  }
@@ -434,9 +423,6 @@ function sandboxFileMetadata(record) {
434
423
  mtime: new Date(revision).toISOString()
435
424
  };
436
425
  }
437
- export function formatValidationIssues(issues) {
438
- return issues.map((issue) => `${issue.path || "/"} ${issue.message}`).join("; ");
439
- }
440
426
  function requiredValidator(reference) {
441
427
  const validate = ajv.getSchema(reference);
442
428
  if (!validate)
@@ -459,125 +445,6 @@ function validationIssue(error) {
459
445
  params: error.params
460
446
  };
461
447
  }
462
- function validateManifestOrigins(value, allowLocal) {
463
- const manifest = asObject(value);
464
- try {
465
- const homepage = new URL(String(manifest.homepage));
466
- if (!secureOrAllowedLocal(homepage, allowLocal)) {
467
- return semanticIssue("/homepage", "must use HTTPS (or loopback HTTP in local mode)");
468
- }
469
- for (const [index, redirect] of manifest.redirect_uris.entries()) {
470
- const url = new URL(String(redirect));
471
- if (url.origin === homepage.origin && !secureOrAllowedLocal(url, allowLocal)) {
472
- return semanticIssue(`/redirect_uris/${index}`, "must use HTTPS (or loopback HTTP in local mode)");
473
- }
474
- const nativeAllowed = nativeRedirectMatchesApplication(url, String(manifest.id));
475
- if (url.origin !== homepage.origin && !nativeAllowed) {
476
- return semanticIssue(`/redirect_uris/${index}`, "must use the homepage origin or a private-use scheme matching the application ID");
477
- }
478
- }
479
- if (manifest.icon !== undefined && new URL(String(manifest.icon)).origin !== homepage.origin) {
480
- return semanticIssue("/icon", "must use the homepage origin");
481
- }
482
- return { valid: true, issues: [] };
483
- }
484
- catch {
485
- return semanticIssue("/", "contains an invalid URL");
486
- }
487
- }
488
- function nativeRedirectMatchesApplication(url, applicationId) {
489
- const scheme = url.protocol.slice(0, -1);
490
- return isNativeRedirectUri(url)
491
- && (scheme === applicationId || scheme.startsWith(`${applicationId}.`));
492
- }
493
- function validateProvisionRequirements(value) {
494
- const manifest = asObject(value);
495
- const requirements = asObject(manifest.requirements);
496
- const requiredContracts = Array.isArray(requirements.contracts) ? requirements.contracts : [];
497
- const required = new Set(requiredContracts.map((contract) => {
498
- const value = asObject(contract);
499
- return `${value.id}@${value.version}`;
500
- }));
501
- const provisions = asObject(manifest.provisions);
502
- const packs = Array.isArray(provisions.type_packs)
503
- ? provisions.type_packs
504
- : [];
505
- for (const [packIndex, provisionValue] of packs.entries()) {
506
- const provision = asObject(provisionValue);
507
- const providedContracts = Array.isArray(provision.provides)
508
- ? provision.provides
509
- : [];
510
- for (const providedValue of providedContracts) {
511
- const provided = asObject(providedValue);
512
- if (!required.has(`${provided.id}@${provided.version}`)) {
513
- return semanticIssue(`/provisions/type_packs/${packIndex}/provides`, "may only contain contracts required by the application");
514
- }
515
- }
516
- const manifest = asObject(provision.manifest);
517
- const declaredResources = Array.isArray(manifest.resources)
518
- ? manifest.resources.map(asObject)
519
- : [];
520
- const embeddedResources = Array.isArray(provision.resources)
521
- ? provision.resources.map(asObject)
522
- : [];
523
- const embedded = new Map(embeddedResources.map((resource) => [
524
- String(resource.source),
525
- resource.document
526
- ]));
527
- if (embedded.size !== embeddedResources.length
528
- || declaredResources.length !== embeddedResources.length) {
529
- return semanticIssue(`/provisions/type_packs/${packIndex}/resources`, "must match manifest source paths exactly");
530
- }
531
- for (const [resourceIndex, resource] of declaredResources.entries()) {
532
- const source = String(resource.source);
533
- const document = embedded.get(source);
534
- if (typeof document !== "string") {
535
- return semanticIssue(`/provisions/type_packs/${packIndex}/resources`, `is missing manifest source ${source}`);
536
- }
537
- const digest = `sha256:${createHash("sha256").update(document).digest("hex")}`;
538
- if (digest !== resource.digest) {
539
- return semanticIssue(`/provisions/type_packs/${packIndex}/manifest/resources/${resourceIndex}/digest`, "does not match the embedded document");
540
- }
541
- }
542
- }
543
- return { valid: true, issues: [] };
544
- }
545
- function localManifestSchemaCandidate(value) {
546
- const candidate = clone(value);
547
- const object = asObject(candidate);
548
- for (const field of ["homepage", "icon"]) {
549
- if (typeof object[field] === "string")
550
- object[field] = schemaSafeLocalUrl(object[field]);
551
- }
552
- if (Array.isArray(object.redirect_uris)) {
553
- object.redirect_uris = object.redirect_uris.map((url) => typeof url === "string" ? schemaSafeLocalUrl(url) : url);
554
- }
555
- return candidate;
556
- }
557
- function schemaSafeLocalUrl(value) {
558
- try {
559
- const url = new URL(value);
560
- if (url.protocol === "http:" && isLoopback(url.hostname))
561
- url.protocol = "https:";
562
- return url.href;
563
- }
564
- catch {
565
- return value;
566
- }
567
- }
568
- function secureOrAllowedLocal(url, allowLocal) {
569
- return url.protocol === "https:"
570
- || (allowLocal && url.protocol === "http:" && isLoopback(url.hostname));
571
- }
572
- function isLoopback(hostname) {
573
- return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]" || hostname === "::1";
574
- }
575
- function semanticIssue(path, message) {
576
- return {
577
- valid: false,
578
- issues: [{ path, keyword: "semantic", message, params: {} }]
579
- };
580
- }
581
448
  function definitionIssue(path, keyword, message) {
582
449
  return { path, keyword, message, params: {} };
583
450
  }
@@ -601,7 +468,7 @@ function sandboxDescription(value = {}) {
601
468
  collection_id: value.collection_id ?? "01900000-0000-7000-8000-000000000001",
602
469
  display_name: value.display_name ?? "Developer sandbox",
603
470
  spec_version: value.spec_version ?? "0.3.0",
604
- operations: value.operations ?? ["describe", "changes", "read", "query", "list_views", "execute_view", "read_view_source", "validate", "create", "update", "delete", "rename", "create_view_source", "update_view_source", "delete_view_source", "read_type", "create_type", "update_type", "apply_type_pack"],
471
+ operations: value.operations ?? ["describe", "changes", "read", "query", "list_views", "execute_view", "read_view_source", "validate", "create", "update", "delete", "rename", "create_view_source", "update_view_source", "delete_view_source", "read_type", "create_type", "update_type", "assess_type_pack", "apply_type_pack"],
605
472
  change_cursor: value.change_cursor ?? 0,
606
473
  types: clone(value.types ?? []),
607
474
  contracts: clone(value.contracts ?? [])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdbase-dev/connect-dev",
3
- "version": "0.1.0-beta.27",
3
+ "version": "0.1.0-beta.29",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@
26
26
  "dependencies": {
27
27
  "ajv": "^8.20.0",
28
28
  "yaml": "^2.9.0",
29
- "@mdbase-dev/connect": "0.1.0-beta.27",
30
- "@mdbase-dev/connect-protocol": "0.1.0-beta.27"
29
+ "@mdbase-dev/connect": "0.1.0-beta.29",
30
+ "@mdbase-dev/connect-protocol": "0.1.0-beta.29"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^24.0.0",
@@ -35,7 +35,7 @@
35
35
  "vitest": "^4.1.10"
36
36
  },
37
37
  "scripts": {
38
- "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json",
38
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node -e \"require('node:fs').chmodSync('dist/cli.js',0o755)\"",
39
39
  "test": "vitest run",
40
40
  "typecheck": "tsc -p tsconfig.json --noEmit"
41
41
  }