@instruments/materialgraph 0.25.0 → 0.27.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.
Files changed (158) hide show
  1. package/association-types.d.ts +38 -27
  2. package/associations-client.d.ts +4 -4
  3. package/associations-client.js +3 -10
  4. package/attribution-types.d.ts +4 -4
  5. package/brand-types.d.ts +14 -6
  6. package/brands-client.d.ts +7 -38
  7. package/brands-client.js +10 -40
  8. package/by-colour-types.d.ts +58 -31
  9. package/by-spec-types.d.ts +6 -73
  10. package/by-spec-types.js +7 -5
  11. package/catalog-discovery-types.d.ts +11 -26
  12. package/catalogue-client.d.ts +16 -35
  13. package/catalogue-client.js +32 -67
  14. package/catalogue-types.d.ts +44 -4
  15. package/categories-client.d.ts +63 -0
  16. package/categories-client.js +48 -0
  17. package/category-types.d.ts +114 -0
  18. package/citation-types.d.ts +4 -4
  19. package/client-config.d.ts +4 -6
  20. package/client-config.js +2 -4
  21. package/client-source-material-comments.d.ts +4 -4
  22. package/client-source-material-comments.js +4 -38
  23. package/client-vocabulary.d.ts +7 -9
  24. package/client-vocabulary.js +22 -30
  25. package/client.d.ts +110 -244
  26. package/client.js +217 -387
  27. package/codes-client.d.ts +2 -2
  28. package/codes-client.js +8 -8
  29. package/codes-types.d.ts +55 -34
  30. package/colour-aggregate-types.d.ts +24 -24
  31. package/colours-client.d.ts +6 -11
  32. package/colours-client.js +11 -19
  33. package/coordinate-client.d.ts +2 -2
  34. package/coordinate-client.js +1 -13
  35. package/corpus-scope-types.d.ts +3 -3
  36. package/corpus-scope-types.js +1 -25
  37. package/demand-batch-types.d.ts +18 -18
  38. package/demand-types.d.ts +24 -24
  39. package/errors.d.ts +13 -13
  40. package/errors.js +54 -52
  41. package/http-transport.d.ts +13 -21
  42. package/http-transport.js +31 -28
  43. package/identify-types.d.ts +54 -44
  44. package/identify-types.js +5 -3
  45. package/index.d.ts +11 -27
  46. package/index.js +4 -6
  47. package/list-variant-facets-types.d.ts +60 -0
  48. package/list-variants-types.d.ts +142 -0
  49. package/list-variants-types.js +12 -0
  50. package/match-stream-types.d.ts +45 -32
  51. package/match-stream-types.js +2 -0
  52. package/match-stream.d.ts +2 -2
  53. package/match-stream.js +67 -49
  54. package/match-types.d.ts +32 -8
  55. package/material-asset-types.d.ts +89 -69
  56. package/material-block-types.d.ts +8 -6
  57. package/material-composition-client.d.ts +21 -0
  58. package/material-composition-client.js +13 -0
  59. package/material-composition-types.d.ts +403 -0
  60. package/material-query-plan-types.d.ts +61 -145
  61. package/material-resources-client.d.ts +12 -10
  62. package/material-resources-client.js +27 -22
  63. package/material-types.d.ts +16 -24
  64. package/ndjson.js +16 -8
  65. package/operations.d.ts +6 -6
  66. package/operations.js +29 -156
  67. package/package.json +5 -1
  68. package/palette-search-types.d.ts +87 -52
  69. package/query-understanding-types.d.ts +65 -40
  70. package/resolve-client.d.ts +8 -12
  71. package/resolve-client.js +9 -13
  72. package/resolve-colour-types.d.ts +8 -8
  73. package/resolve-types.d.ts +10 -10
  74. package/response-schemas.d.ts +20 -0
  75. package/response-schemas.generated.d.ts +5 -0
  76. package/response-schemas.generated.js +160 -0
  77. package/response-schemas.js +113 -0
  78. package/run-types.d.ts +64 -145
  79. package/runs.d.ts +9 -58
  80. package/runs.js +60 -149
  81. package/samplize-catalogue-types.d.ts +18 -18
  82. package/samplize-colorvec.d.ts +20 -20
  83. package/samplize-colorvec.js +66 -42
  84. package/schema-resource-types.d.ts +52 -39
  85. package/schema-resource-types.js +5 -5
  86. package/search-card-types.d.ts +26 -4
  87. package/search-index-plan-types.d.ts +70 -0
  88. package/search-refinement-types.d.ts +10 -40
  89. package/search-refinement-types.js +1 -0
  90. package/search-request-types.d.ts +121 -204
  91. package/search-response-receipt-types.d.ts +13 -253
  92. package/search-response-types.d.ts +2 -2
  93. package/search-result-validation.d.ts +3 -19
  94. package/search-result-validation.js +42 -183
  95. package/source-material-validation.d.ts +3 -3
  96. package/source-material-validation.js +35 -39
  97. package/spec-facet-types.d.ts +11 -16
  98. package/spec-types.d.ts +23 -16
  99. package/spec-types.js +8 -7
  100. package/specifications.d.ts +14 -72
  101. package/specifications.js +39 -89
  102. package/sse.d.ts +2 -2
  103. package/sse.js +32 -16
  104. package/substitute-types.d.ts +22 -22
  105. package/suggest-types.d.ts +11 -17
  106. package/suggest-types.js +3 -3
  107. package/taxonomy-coverage-types.d.ts +8 -8
  108. package/types.d.ts +202 -405
  109. package/validation.d.ts +26 -26
  110. package/validation.js +97 -92
  111. package/webmcp.d.ts +3 -3
  112. package/webmcp.generated.js +10 -93
  113. package/brand-most-sampled-types.d.ts +0 -33
  114. package/browse-types.d.ts +0 -236
  115. package/client-browse.d.ts +0 -78
  116. package/client-browse.js +0 -72
  117. package/client-exploration.d.ts +0 -9
  118. package/client-exploration.js +0 -7
  119. package/compare-types.d.ts +0 -89
  120. package/composition-client.d.ts +0 -33
  121. package/composition-client.js +0 -27
  122. package/composition-types.d.ts +0 -455
  123. package/composition-types.js +0 -10
  124. package/correction-types.d.ts +0 -88
  125. package/exploration-types.d.ts +0 -118
  126. package/exploration-types.js +0 -1
  127. package/fan-deck-types.d.ts +0 -42
  128. package/fan-deck-types.js +0 -9
  129. package/match-rejection-types.d.ts +0 -43
  130. package/match-rejection-types.js +0 -7
  131. package/palette-completion-types.d.ts +0 -115
  132. package/palette-completion-types.js +0 -1
  133. package/project-types.d.ts +0 -79
  134. package/project-types.js +0 -9
  135. package/projects.d.ts +0 -13
  136. package/projects.js +0 -46
  137. package/render-assets-types.d.ts +0 -65
  138. package/render-assets-types.js +0 -1
  139. package/run-events.d.ts +0 -106
  140. package/run-events.js +0 -32
  141. package/schedule-reference-types.d.ts +0 -46
  142. package/schedule-reference-types.js +0 -1
  143. package/schedule-references-client.d.ts +0 -14
  144. package/schedule-references-client.js +0 -26
  145. package/schedule-types.d.ts +0 -261
  146. package/schedule-types.js +0 -1
  147. package/search-collapse-types.d.ts +0 -69
  148. package/search-collapse-types.js +0 -1
  149. package/search-mood-types.d.ts +0 -6
  150. package/search-mood-types.js +0 -1
  151. package/search-window-types.d.ts +0 -25
  152. package/search-window-types.js +0 -1
  153. package/slot-pool-types.d.ts +0 -372
  154. package/slot-pool-types.js +0 -1
  155. /package/{brand-most-sampled-types.js → category-types.js} +0 -0
  156. /package/{browse-types.js → list-variant-facets-types.js} +0 -0
  157. /package/{compare-types.js → material-composition-types.js} +0 -0
  158. /package/{correction-types.js → search-index-plan-types.js} +0 -0
package/http-transport.js CHANGED
@@ -8,13 +8,14 @@
8
8
  */
9
9
  import { MaterialGraphError } from "./errors.js";
10
10
  import { operationPath } from "./operations.js";
11
- function parseIntOrNull(value) {
12
- if (value === null)
11
+ const parseIntOrNull = (value) => {
12
+ if (value === null) {
13
13
  return null;
14
+ }
14
15
  const parsed = Number.parseInt(value, 10);
15
16
  return Number.isNaN(parsed) ? null : parsed;
16
- }
17
- function parseRateLimit(headers) {
17
+ };
18
+ const parseRateLimit = (headers) => {
18
19
  const limit = parseIntOrNull(headers.get("x-ratelimit-limit"));
19
20
  const remaining = parseIntOrNull(headers.get("x-ratelimit-remaining"));
20
21
  const reset = parseIntOrNull(headers.get("x-ratelimit-reset"));
@@ -26,7 +27,7 @@ function parseRateLimit(headers) {
26
27
  return null;
27
28
  }
28
29
  return { limit, remaining, reset, retryAfter };
29
- }
30
+ };
30
31
  export class HttpTransport {
31
32
  baseUrl;
32
33
  apiKey;
@@ -34,7 +35,7 @@ export class HttpTransport {
34
35
  #lastRateLimit = null;
35
36
  constructor(options) {
36
37
  this.apiKey = options.apiKey;
37
- this.baseUrl = options.baseUrl.replace(/\/+$/, "");
38
+ this.baseUrl = options.baseUrl.replace(/\/+$/u, "");
38
39
  this.fetch = options.fetch;
39
40
  }
40
41
  get lastRateLimit() {
@@ -43,8 +44,8 @@ export class HttpTransport {
43
44
  /** The bearer + JSON `Accept` headers, plus any per-request additions. */
44
45
  authHeaders(extra) {
45
46
  return {
46
- Authorization: `Bearer ${this.apiKey}`,
47
47
  Accept: "application/json",
48
+ Authorization: `Bearer ${this.apiKey}`,
48
49
  ...extra,
49
50
  };
50
51
  }
@@ -52,12 +53,14 @@ export class HttpTransport {
52
53
  const url = new URL(`${this.baseUrl}${path}`);
53
54
  if (query) {
54
55
  for (const [key, value] of Object.entries(query)) {
55
- if (value === undefined || value === null)
56
+ if (value === undefined || value === null) {
56
57
  continue;
58
+ }
57
59
  if (Array.isArray(value)) {
58
60
  for (const item of value) {
59
- if (item !== undefined && item !== null)
61
+ if (item !== undefined && item !== null) {
60
62
  url.searchParams.append(key, String(item));
63
+ }
61
64
  }
62
65
  }
63
66
  else {
@@ -83,17 +86,17 @@ export class HttpTransport {
83
86
  let response;
84
87
  try {
85
88
  response = await this.fetch(input.url, {
86
- method: input.method,
87
- headers: input.headers,
88
89
  body: input.body,
90
+ headers: input.headers,
91
+ method: input.method,
89
92
  signal: input.signal,
90
93
  });
91
94
  }
92
95
  catch (cause) {
93
96
  throw MaterialGraphError.fromTransport({
94
97
  ...metadata,
95
- cause,
96
98
  callerSignal: input.signal,
99
+ cause,
97
100
  });
98
101
  }
99
102
  const rateLimit = parseRateLimit(response.headers);
@@ -105,8 +108,8 @@ export class HttpTransport {
105
108
  catch (cause) {
106
109
  throw MaterialGraphError.fromTransport({
107
110
  ...metadata,
108
- cause,
109
111
  callerSignal: input.signal,
112
+ cause,
110
113
  });
111
114
  }
112
115
  let parsed;
@@ -121,15 +124,15 @@ export class HttpTransport {
121
124
  if (!response.ok) {
122
125
  throw MaterialGraphError.fromResponse({
123
126
  ...metadata,
124
- status: response.status,
125
- body: parsed,
126
- responseText: text,
127
- rateLimit,
128
127
  apiKey: this.apiKey,
128
+ body: parsed,
129
129
  queryValues: [...requestUrl.searchParams.values()],
130
+ rateLimit,
131
+ responseText: text,
132
+ status: response.status,
130
133
  });
131
134
  }
132
- return { response, text, parsed };
135
+ return { parsed, response, text };
133
136
  }
134
137
  /**
135
138
  * Open a streaming operation and hand back its UNREAD byte body — the one
@@ -152,20 +155,20 @@ export class HttpTransport {
152
155
  let response;
153
156
  try {
154
157
  response = await this.fetch(url, {
155
- method: sdkOperation.method,
158
+ body: hasBody ? JSON.stringify(options.body) : undefined,
156
159
  headers: this.authHeaders({
157
160
  Accept: options.accept,
158
161
  ...(hasBody ? { "Content-Type": "application/json" } : {}),
159
162
  }),
160
- body: hasBody ? JSON.stringify(options.body) : undefined,
163
+ method: sdkOperation.method,
161
164
  signal: options.signal,
162
165
  });
163
166
  }
164
167
  catch (cause) {
165
168
  throw MaterialGraphError.fromTransport({
166
169
  ...metadata,
167
- cause,
168
170
  callerSignal: options.signal,
171
+ cause,
169
172
  });
170
173
  }
171
174
  const rateLimit = parseRateLimit(response.headers);
@@ -191,12 +194,12 @@ export class HttpTransport {
191
194
  }
192
195
  throw MaterialGraphError.fromResponse({
193
196
  ...metadata,
194
- status: response.status,
195
- body: parsed,
196
- responseText: text,
197
- rateLimit,
198
197
  apiKey: this.apiKey,
198
+ body: parsed,
199
199
  queryValues: [...requestUrl.searchParams.values()],
200
+ rateLimit,
201
+ responseText: text,
202
+ status: response.status,
200
203
  });
201
204
  }
202
205
  if (response.body === null) {
@@ -209,16 +212,16 @@ export class HttpTransport {
209
212
  const url = this.buildUrl(operationPath(sdkOperation, options.pathParams), options.query);
210
213
  const hasBody = options.body !== undefined;
211
214
  const { parsed } = await this.send({
212
- method: sdkOperation.method,
213
- url,
215
+ body: hasBody ? JSON.stringify(options.body) : undefined,
214
216
  headers: this.authHeaders({
215
217
  ...(hasBody ? { "Content-Type": "application/json" } : {}),
216
218
  ...(options.idempotencyKey
217
219
  ? { "Idempotency-Key": options.idempotencyKey }
218
220
  : {}),
219
221
  }),
220
- body: hasBody ? JSON.stringify(options.body) : undefined,
222
+ method: sdkOperation.method,
221
223
  signal: options.signal,
224
+ url,
222
225
  });
223
226
  return parsed;
224
227
  }
@@ -1,72 +1,82 @@
1
1
  /**
2
- * Public wire types for `POST /api/v1/identify`.
2
+ * Public wire types for `POST /api/v1/identify` (MG-1672's `resolve_variant`
3
+ * contract).
3
4
  *
4
- * These intentionally mirror the domain-owned Zod contract rather than
5
- * importing it: the published SDK must carry no workspace package dependency.
5
+ * These intentionally mirror the domain-owned Zod contract
6
+ * (`@materialgraph/products/identify-contract`) rather than importing it: the
7
+ * published SDK must carry no workspace package dependency.
6
8
  */
7
- export interface IdentifySelectedPageInput {
8
- url: string;
9
- title?: string;
10
- selectedText?: string;
11
- productLabels?: string[];
12
- brandLabels?: string[];
13
- /** Manufacturer code visibly supplied by the selected page. */
14
- manufacturerCode?: string;
15
- imageUrls?: string[];
16
- colourHexes?: string[];
17
- }
18
- export interface IdentifySelectedPageSubject {
19
- kind: "variant" | "product" | "brand";
9
+ /**
10
+ * What `mg.identify()` accepts. Give `url` alone, or `code` with `brandId`
11
+ * (from `mg.brands()`) when there is no page to read. `labels` are product
12
+ * names visible on the page, sent only to tell several URL candidates apart -
13
+ * they never widen a search or invent an identity on their own.
14
+ */
15
+ export type IdentifyVariantInput = {
16
+ url?: string;
17
+ code?: string;
18
+ brandId?: string;
19
+ labels?: string[];
20
+ };
21
+ /** One identified, placed or bounded-candidate subject. */
22
+ export type IdentifySubject = {
23
+ kind: "variant" | "brand";
20
24
  id: string;
21
25
  name: string;
26
+ code?: string;
22
27
  brand?: {
23
28
  id: string;
24
29
  name: string;
25
- slug: string;
26
30
  };
27
- }
28
- export interface IdentifySelectedPageEvidence {
29
- kind: "manufacturer-url" | "brand-homepage" | "visible-identity" | "visual" | "colour";
31
+ };
32
+ /** What stood behind an outcome. Exact and scoreless: never a similarity guess. */
33
+ export type IdentifyEvidence = {
34
+ kind: "manufacturer-url" | "brand-homepage" | "manufacturer-code" | "visible-label";
30
35
  url?: string;
31
36
  detail: string;
32
- }
33
- interface IdentifySelectedPageDataBase {
34
- receipt: {
35
- submittedUrl: string;
36
- normalizedUrl: string;
37
- normalizationSteps: string[];
38
- };
39
- evidence: IdentifySelectedPageEvidence[];
40
- }
41
- export type IdentifySelectedPageData = (IdentifySelectedPageDataBase & {
37
+ };
38
+ /** The submitted URL, normalised, and the steps that normalisation took. Absent for a code-only call. */
39
+ export type IdentifyReceipt = {
40
+ submittedUrl: string;
41
+ normalizedUrl: string;
42
+ normalizationSteps: string[];
43
+ };
44
+ type IdentifyResultBase = {
45
+ evidence: IdentifyEvidence[];
46
+ receipt?: IdentifyReceipt;
47
+ };
48
+ /**
49
+ * Why nothing was identified. Absent and empty differ: this names what was
50
+ * looked for and not found, never a similarity guess.
51
+ */
52
+ export type IdentifyUnresolvedReason = "no-stored-url" | "no-code-match";
53
+ /** Exact identities only - no rung carries a similarity score. */
54
+ export type IdentifyResult = (IdentifyResultBase & {
42
55
  outcome: "identified";
43
- rung: "lookup" | "disambiguate";
44
- subject: IdentifySelectedPageSubject & {
56
+ subject: IdentifySubject & {
45
57
  kind: "variant";
46
58
  };
47
- }) | (IdentifySelectedPageDataBase & {
59
+ }) | (IdentifyResultBase & {
48
60
  outcome: "placed";
49
- rung: "lookup";
50
- subject: IdentifySelectedPageSubject & {
51
- kind: "product" | "brand";
61
+ subject: IdentifySubject & {
62
+ kind: "brand";
52
63
  };
53
- }) | (IdentifySelectedPageDataBase & {
64
+ }) | (IdentifyResultBase & {
54
65
  outcome: "ambiguous";
55
- rung: "lookup" | "disambiguate" | "match" | "color";
56
- candidates: IdentifySelectedPageSubject[];
66
+ candidates: IdentifySubject[];
57
67
  truncated: boolean;
58
- }) | (IdentifySelectedPageDataBase & {
68
+ }) | (IdentifyResultBase & {
59
69
  outcome: "unresolved";
60
- rung?: "match" | "color";
70
+ reason: IdentifyUnresolvedReason;
61
71
  });
62
72
  /** The canonical callable-operation envelope returned by `identify()`. */
63
- export interface IdentifySelectedPageResult {
64
- data: IdentifySelectedPageData;
73
+ export type IdentifyResponse = {
74
+ data: IdentifyResult;
65
75
  meta: {
66
76
  operationId: "retrieval.identify";
67
77
  requestId: string;
68
78
  };
69
79
  links: Record<string, never>;
70
80
  warnings: [];
71
- }
81
+ };
72
82
  export {};
package/identify-types.js CHANGED
@@ -1,7 +1,9 @@
1
1
  /**
2
- * Public wire types for `POST /api/v1/identify`.
2
+ * Public wire types for `POST /api/v1/identify` (MG-1672's `resolve_variant`
3
+ * contract).
3
4
  *
4
- * These intentionally mirror the domain-owned Zod contract rather than
5
- * importing it: the published SDK must carry no workspace package dependency.
5
+ * These intentionally mirror the domain-owned Zod contract
6
+ * (`@materialgraph/products/identify-contract`) rather than importing it: the
7
+ * published SDK must carry no workspace package dependency.
6
8
  */
7
9
  export {};
package/index.d.ts CHANGED
@@ -1,34 +1,23 @@
1
- export { MaterialGraphClient, DEFAULT_BASE_URL, MAX_BATCH_IDS, } from "./client.js";
2
- export type { CompareInput, CompareTarget, CompareCell, CompareResult, CompareResponse, } from "./compare-types.js";
3
- export type { CorrectionJson, CorrectionSubject, CorrectionTarget, CorrectionEvidence, CreateCorrectionInput, Correction, CorrectionResponse, CorrectionsListResponse, } from "./correction-types.js";
4
- export type { MaterialGraphClientOptions, BrowseNamespace, ExplorationNamespace, SourceMaterialCommentsNamespace, } from "./client.js";
1
+ export { MaterialGraphClient, DEFAULT_BASE_URL } from "./client.js";
2
+ export type { MaterialGraphClientOptions, SourceMaterialCommentsNamespace, } from "./client.js";
3
+ export type * from "./list-variants-types.js";
4
+ export type * from "./list-variant-facets-types.js";
5
5
  export { MATERIALGRAPH_API_VERSION, SDK_OPERATIONS } from "./operations.js";
6
6
  export type { SdkOperation, SdkOperationId } from "./operations.js";
7
7
  export type * from "./identifiers.js";
8
- export type * from "./exploration-types.js";
9
8
  export { TERMINAL_RUN_EVENT_TYPES } from "./run-types.js";
10
9
  export type * from "./run-types.js";
11
- export type * from "./schedule-types.js";
12
10
  export type * from "./citation-types.js";
13
- export { VARY_AXES } from "./composition-types.js";
14
- export type * from "./composition-types.js";
15
- export type * from "./slot-pool-types.js";
16
- export { PROJECT_EVENT_KINDS } from "./project-types.js";
17
- export type * from "./project-types.js";
18
- export { COMPOSITION_PHASE_EVENT_TYPES, COMPOSITION_PROGRAMME_EVENT_TYPES, COMPOSITION_REVIEW_CRITERIA_EVENT_TYPES, parseRunEvent, } from "./run-events.js";
19
- export type * from "./run-events.js";
11
+ export type * from "./material-composition-types.js";
20
12
  export { MATERIALGRAPH_PROBLEM_EXTENSIONS, MaterialGraphError, } from "./errors.js";
21
13
  export type { MaterialGraphErrorInit, MaterialGraphErrorKind, MaterialGraphRequestMetadata, ProblemDetail, RateLimit, SanitizedErrorValue, SanitizedIssue, SimpleErrorBody, } from "./errors.js";
22
14
  export type * from "./types.js";
23
- export type * from "./search-collapse-types.js";
24
15
  export type * from "./search-card-types.js";
25
- export type * from "./match-types.js";
26
16
  export type * from "./identify-types.js";
27
- export type * from "./browse-types.js";
28
17
  export type * from "./catalogue-types.js";
29
18
  export type * from "./by-colour-types.js";
30
- export { MATCH_IMAGE_TYPES, MATCH_OUTCOMES, MATCH_MATERIAL_FUNCTIONS, MATCH_STREAM_EVENT_TYPES, MATCH_SURFACE_STATUSES, MATCH_WORKFLOW_STEPS, } from "./match-stream-types.js";
31
- export type * from "./match-stream-types.js";
19
+ export { CategoriesClient } from "./categories-client.js";
20
+ export type * from "./category-types.js";
32
21
  export { CodesClient } from "./codes-client.js";
33
22
  export type * from "./codes-types.js";
34
23
  export { ColoursClient } from "./colours-client.js";
@@ -36,24 +25,19 @@ export type { ColoursTransport } from "./colours-client.js";
36
25
  export type * from "./colour-aggregate-types.js";
37
26
  export type * from "./palette-search-types.js";
38
27
  export type * from "./query-understanding-types.js";
28
+ export type * from "./match-types.js";
29
+ export { MATCH_ERROR_REASONS, MATCH_IMAGE_TYPES, MATCH_OUTCOMES, MATCH_MATERIAL_FUNCTIONS, MATCH_STREAM_EVENT_TYPES, MATCH_SURFACE_STATUSES, MATCH_WORKFLOW_STEPS, } from "./match-stream-types.js";
30
+ export type * from "./match-stream-types.js";
39
31
  export type * from "./material-query-plan-types.js";
40
32
  export type * from "./association-types.js";
41
33
  export type * from "./brand-types.js";
42
- export type * from "./fan-deck-types.js";
43
34
  export type * from "./material-asset-types.js";
44
- export type * from "./render-assets-types.js";
45
35
  export type * from "./material-block-types.js";
46
36
  export type * from "./schema-resource-types.js";
47
37
  export type * from "./taxonomy-coverage-types.js";
48
- export type * from "./schedule-reference-types.js";
49
- export type * from "./substitute-types.js";
50
38
  export type * from "./search-refinement-types.js";
51
- export type * from "./search-window-types.js";
52
39
  export type * from "./attribution-types.js";
53
- export type * from "./match-rejection-types.js";
54
40
  export { CERTIFICATION_PROGRAMME_ATTRIBUTE_ID } from "./spec-types.js";
55
41
  export type * from "./spec-types.js";
56
- export { certificationProgramme, certificationProgrammeCriterion, hasSpec, specCriterion, specRangeCriterion, specTerm, } from "./specifications.js";
42
+ export { certificationProgramme, hasSpec, specTerm } from "./specifications.js";
57
43
  export type { SamplizePublicationSource, SamplizeLrvObservation, SamplizeDemand, SamplizeCollectionMembership, SamplizeCatalogueOptions, SamplizeCataloguePage, SamplizeCatalogueProduct, SamplizeHexObservation, } from "./samplize-catalogue-types.js";
58
- export type { PaletteCompleteInput, PaletteCompleteResponse, PaletteDiscoverInput, PaletteDiscoverResponse, } from "./palette-completion-types.js";
59
- export type { BrandMostSampledResponse } from "./brand-most-sampled-types.js";
package/index.js CHANGED
@@ -1,12 +1,10 @@
1
- export { MaterialGraphClient, DEFAULT_BASE_URL, MAX_BATCH_IDS, } from "./client.js";
1
+ export { MaterialGraphClient, DEFAULT_BASE_URL } from "./client.js";
2
2
  export { MATERIALGRAPH_API_VERSION, SDK_OPERATIONS } from "./operations.js";
3
3
  export { TERMINAL_RUN_EVENT_TYPES } from "./run-types.js";
4
- export { VARY_AXES } from "./composition-types.js";
5
- export { PROJECT_EVENT_KINDS } from "./project-types.js";
6
- export { COMPOSITION_PHASE_EVENT_TYPES, COMPOSITION_PROGRAMME_EVENT_TYPES, COMPOSITION_REVIEW_CRITERIA_EVENT_TYPES, parseRunEvent, } from "./run-events.js";
7
4
  export { MATERIALGRAPH_PROBLEM_EXTENSIONS, MaterialGraphError, } from "./errors.js";
8
- export { MATCH_IMAGE_TYPES, MATCH_OUTCOMES, MATCH_MATERIAL_FUNCTIONS, MATCH_STREAM_EVENT_TYPES, MATCH_SURFACE_STATUSES, MATCH_WORKFLOW_STEPS, } from "./match-stream-types.js";
5
+ export { CategoriesClient } from "./categories-client.js";
9
6
  export { CodesClient } from "./codes-client.js";
10
7
  export { ColoursClient } from "./colours-client.js";
8
+ export { MATCH_ERROR_REASONS, MATCH_IMAGE_TYPES, MATCH_OUTCOMES, MATCH_MATERIAL_FUNCTIONS, MATCH_STREAM_EVENT_TYPES, MATCH_SURFACE_STATUSES, MATCH_WORKFLOW_STEPS, } from "./match-stream-types.js";
11
9
  export { CERTIFICATION_PROGRAMME_ATTRIBUTE_ID } from "./spec-types.js";
12
- export { certificationProgramme, certificationProgrammeCriterion, hasSpec, specCriterion, specRangeCriterion, specTerm, } from "./specifications.js";
10
+ export { certificationProgramme, hasSpec, specTerm } from "./specifications.js";
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @module list-variant-facets-types
3
+ * @description Hand-maintained mirror of `list_variant_facets`'s (MG-2294)
4
+ * input and output wire shapes. The source of truth is
5
+ * `packages/products/src/variants/list-variant-facets.ts` (the input) and
6
+ * `list-variant-facets-contract.ts` (the output); this SDK has no runtime
7
+ * dependency on `@materialgraph/products`, so the shapes are copied here and
8
+ * `contract-parity.test.ts` keeps them honest.
9
+ */
10
+ import type { CorpusScope } from "./corpus-scope-types.js";
11
+ import type { FilterGroups } from "./list-variants-types.js";
12
+ export type ListVariantFacetsInput = {
13
+ /** 1–10 facetable attribute ids. Find them with `listAttributes()`. */
14
+ attributeIds: string[];
15
+ /** The same kind-grouped filter tree `listVariants()` takes. */
16
+ /** Count only this corpus scope; absent or `all` counts every variant. */
17
+ corpusScope?: CorpusScope;
18
+ filters?: FilterGroups;
19
+ /** Top values per categorical or boolean facet, 1–50. Defaults to 10. */
20
+ valuesPerFacet?: number;
21
+ };
22
+ export type VariantFacetValue = {
23
+ /** The canonical value `listVariants()`' `filters` accepts for this attribute. */
24
+ value: string;
25
+ label: string;
26
+ /** Distinct eligible variants under the supplied filters carrying this value. */
27
+ variantCount: number;
28
+ };
29
+ type VariantFacetBase = {
30
+ attributeId: string;
31
+ name: string;
32
+ /** Eligible variants recording no accepted value: unknown, never false or zero. */
33
+ missingVariantCount: number;
34
+ };
35
+ export type CategoricalVariantFacet = VariantFacetBase & {
36
+ kind: "categorical";
37
+ values: VariantFacetValue[];
38
+ /** More observed values exist than `values` shows. */
39
+ hasMoreValues: boolean;
40
+ };
41
+ export type BooleanVariantFacet = VariantFacetBase & {
42
+ kind: "boolean";
43
+ values: VariantFacetValue[];
44
+ hasMoreValues: boolean;
45
+ };
46
+ export type NumericVariantFacet = VariantFacetBase & {
47
+ kind: "numeric";
48
+ /** Observed minimum in the attribute's canonical unit; null when no variant records a value. */
49
+ min: number | null;
50
+ max: number | null;
51
+ unitId: string | null;
52
+ };
53
+ export type VariantFacet = CategoricalVariantFacet | BooleanVariantFacet | NumericVariantFacet;
54
+ export type ListVariantFacetsOutput = {
55
+ /** Eligible variants matching every hard condition: the denominator of every count. */
56
+ matchedVariantCount: number;
57
+ /** One per requested attribute, in request order. */
58
+ facets: VariantFacet[];
59
+ };
60
+ export {};
@@ -0,0 +1,142 @@
1
+ /**
2
+ * @module list-variants-types
3
+ * @description Hand-maintained mirror of `list_variants`'s (MG-2222) input and
4
+ * output wire shapes. The source of truth is
5
+ * `packages/products/src/variants/variant-conditions.ts` (the filter grammar)
6
+ * and `packages/products/src/variants/list-variants-contract.ts` (the output),
7
+ * but this SDK has no RUNTIME dependency on `@materialgraph/products` (it's a
8
+ * devDependency only, for the parity tests in `__tests__/`), so the shapes are
9
+ * copied here rather than imported. `contract-parity.test.ts` keeps this
10
+ * mirror honest against the server types.
11
+ */
12
+ import type { CorpusScope } from "./corpus-scope-types.js";
13
+ export type FilterOp = "in" | "not_in" | "all" | "exists" | "missing" | "eq" | "gt" | "gte" | "lt" | "lte";
14
+ export type FilterTermCondition = {
15
+ field: string;
16
+ op: "in" | "all" | "not_in";
17
+ values: string[];
18
+ };
19
+ export type FilterNumericCondition = {
20
+ field: string;
21
+ op: "eq" | "gt" | "gte" | "lt" | "lte";
22
+ value: number;
23
+ };
24
+ export type FilterPresenceCondition = {
25
+ field: string;
26
+ op: "exists" | "missing";
27
+ };
28
+ /**
29
+ * One filter condition, whichever of the three fully-required shapes. No
30
+ * `unit` key (a numeric value is in the attribute's own canonical unit).
31
+ */
32
+ export type FilterCondition = FilterTermCondition | FilterNumericCondition | FilterPresenceCondition;
33
+ /**
34
+ * `filters`: kind-grouped, not a flat list (MG-2222) — `{terms, numbers,
35
+ * presence}`. Every condition across all three arrays must match (AND); OR
36
+ * within one field is `in`. Send only the arrays you need; an omitted or
37
+ * empty array carries no conditions.
38
+ */
39
+ export type FilterGroups = {
40
+ terms?: FilterTermCondition[];
41
+ numbers?: FilterNumericCondition[];
42
+ presence?: FilterPresenceCondition[];
43
+ };
44
+ /** `optionalFilters`: the same kind-grouped shape as `filters`, with every entry also carrying a required `weight` (1–10). Ranks matched items; never excludes. */
45
+ export type OptionalFilterGroups = {
46
+ terms?: (FilterTermCondition & {
47
+ weight: number;
48
+ })[];
49
+ numbers?: (FilterNumericCondition & {
50
+ weight: number;
51
+ })[];
52
+ presence?: (FilterPresenceCondition & {
53
+ weight: number;
54
+ })[];
55
+ };
56
+ export type OrderByEntry = {
57
+ direction: "asc" | "desc";
58
+ /** A numeric attribute id. */
59
+ field: string;
60
+ };
61
+ export type ListVariantsInclude = "image" | "url";
62
+ export type ListVariantsInput = {
63
+ /** Attribute ids to project under each item's `specifications`. */
64
+ attributes?: string[];
65
+ /**
66
+ * Only variants in this corpus scope: the rows, the page and the cursor.
67
+ * Absent or `all` is every variant.
68
+ */
69
+ corpusScope?: CorpusScope;
70
+ cursor?: string;
71
+ /** Every condition, across `terms`/`numbers`/`presence`, must match. */
72
+ filters?: FilterGroups;
73
+ include?: ListVariantsInclude[];
74
+ /** 1–50; defaults to 10. */
75
+ limit?: number;
76
+ /**
77
+ * Find by name (MG-2222): every word must start a word of the product or
78
+ * variant name. Combines with `filters` as an additional AND condition;
79
+ * ambiguous matches are all returned rather than guessed between.
80
+ */
81
+ name?: string;
82
+ /** Rank only — never excludes. */
83
+ optionalFilters?: OptionalFilterGroups;
84
+ orderBy?: OrderByEntry[];
85
+ };
86
+ /**
87
+ * `score` sums the weights of the matched `optionalFilters`; `matched` lists
88
+ * their positions in the flattened terms-then-numbers-then-presence order
89
+ * the server reads `optionalFilters` in, not the caller's own array shape.
90
+ */
91
+ export type ListVariantsPreference = {
92
+ matched: number[];
93
+ score: number;
94
+ };
95
+ /** `{ [blockId]: { [attributeId]: value } }`. Null means the value is unknown. */
96
+ export type ListVariantsSpecifications = Record<string, Record<string, unknown>>;
97
+ export type ListVariantsNotApplicable = {
98
+ attributes?: string[];
99
+ blocks?: string[];
100
+ };
101
+ /**
102
+ * One list item: the compact identity needed to pick a variant, with image
103
+ * and maker page only when requested (`include`) and selected attributes
104
+ * under `specifications`. Leaner than `get_variant`'s item on purpose.
105
+ */
106
+ export type ListVariantsItem = {
107
+ category: string;
108
+ code: string | null;
109
+ image?: string | null;
110
+ maker: {
111
+ id: string;
112
+ name: string;
113
+ };
114
+ /** The variant's Material Bank SKU. Absent means none is recorded. */
115
+ materialBankId?: string;
116
+ name: string;
117
+ notApplicable?: ListVariantsNotApplicable;
118
+ preference?: ListVariantsPreference;
119
+ product: {
120
+ id: string;
121
+ name: string;
122
+ };
123
+ specifications?: ListVariantsSpecifications;
124
+ url?: string | null;
125
+ /**
126
+ * The eligible variants of this item's product, the set `listVariants`
127
+ * pages. Absent when none is counted.
128
+ */
129
+ variantCount?: number;
130
+ variantId: string;
131
+ };
132
+ export type ListVariantsOutput = {
133
+ items: ListVariantsItem[];
134
+ pageInfo: {
135
+ endCursor: string | null;
136
+ hasNextPage: boolean;
137
+ };
138
+ /** False: nothing from this page on meets any `optionalFilters` entry. Absent when not measured. */
139
+ preferenceMatchesRemain?: boolean;
140
+ /** Explicit `{field: "variant", op: "in"}` ids anywhere in `filters.terms` that did not resolve to an eligible variant in the requested `corpusScope`. */
141
+ unresolvedVariantIds?: string[];
142
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module list-variants-types
3
+ * @description Hand-maintained mirror of `list_variants`'s (MG-2222) input and
4
+ * output wire shapes. The source of truth is
5
+ * `packages/products/src/variants/variant-conditions.ts` (the filter grammar)
6
+ * and `packages/products/src/variants/list-variants-contract.ts` (the output),
7
+ * but this SDK has no RUNTIME dependency on `@materialgraph/products` (it's a
8
+ * devDependency only, for the parity tests in `__tests__/`), so the shapes are
9
+ * copied here rather than imported. `contract-parity.test.ts` keeps this
10
+ * mirror honest against the server types.
11
+ */
12
+ export {};