@instruments/materialgraph 3.1.0 → 3.3.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/association-types.d.ts +20 -20
- package/baseline-types.d.ts +112 -0
- package/baseline-types.js +1 -0
- package/brand-types.d.ts +6 -6
- package/by-spec-types.d.ts +6 -6
- package/catalog-discovery-types.d.ts +4 -4
- package/categories-client.d.ts +3 -3
- package/category-types.d.ts +18 -18
- package/client-config.d.ts +2 -2
- package/client-response-schema.d.ts +2 -2
- package/client-response-schema.js +5 -5
- package/client-vocabulary.d.ts +2 -0
- package/client-vocabulary.js +9 -1
- package/client.d.ts +32 -3
- package/client.js +54 -14
- package/color-profiles-types.d.ts +8 -8
- package/color-wire-types.d.ts +6 -6
- package/colors-client.d.ts +3 -3
- package/discovery-context-types.d.ts +8 -8
- package/errors.d.ts +12 -13
- package/errors.js +84 -74
- package/find-sampled-together-types.d.ts +6 -6
- package/find-variants-by-color-types.d.ts +31 -30
- package/find-variants-by-vector-types.d.ts +13 -13
- package/get-variant-demand-types.d.ts +69 -0
- package/get-variant-demand-types.js +1 -0
- package/get-variant-types.d.ts +7 -7
- package/http-transport.d.ts +14 -10
- package/http-transport.js +14 -12
- package/image-reference-types.d.ts +2 -2
- package/index.d.ts +3 -1
- package/json.d.ts +18 -0
- package/json.js +36 -0
- package/list-enum-values-types.d.ts +8 -8
- package/list-sampled-together-pairs-types.d.ts +11 -11
- package/list-variant-facets-types.d.ts +8 -8
- package/list-variants-types.d.ts +42 -32
- package/material-asset-types.d.ts +26 -26
- package/material-block-types.d.ts +7 -7
- package/material-types.d.ts +6 -6
- package/nearest-paints-types.d.ts +8 -8
- package/operation-responses.d.ts +8 -2
- package/operations.d.ts +1 -1
- package/operations.generated.d.ts +1 -1
- package/operations.generated.js +9 -0
- package/operations.js +1 -1
- package/package.json +1 -1
- package/parse-operation-response.d.ts +4 -3
- package/parse-operation-response.js +112 -135
- package/resolve-color-types.d.ts +6 -6
- package/resolve-variant-types.d.ts +10 -10
- package/response-schema-catalog.d.ts +8 -0
- package/response-schema-catalog.js +82 -0
- package/response-schemas.d.ts +32 -3
- package/response-schemas.generated.d.ts +1 -1
- package/response-schemas.generated.js +34 -28
- package/response-schemas.js +5 -77
- package/schema-resource-types.d.ts +12 -12
- package/search-catalog-subset-types.d.ts +2 -2
- package/search-variants-types.d.ts +12 -12
- package/source-material-types.d.ts +6 -6
- package/source-material.js +2 -32
- package/types.d.ts +43 -45
- package/webmcp.d.ts +10 -4
- package/webmcp.generated.js +5 -4
|
@@ -15,7 +15,7 @@ import type { ImageReferenceInput } from "./image-reference-types.js";
|
|
|
15
15
|
import type { SearchCatalogSubset, SearchCatalogSubsetReceipt } from "./search-catalog-subset-types.js";
|
|
16
16
|
export type FindVariantsByColorMode = "contains" | "palette" | "rerank";
|
|
17
17
|
/** One color condition. `role` defaults to `required`; every other field defaults to absent/false/0. */
|
|
18
|
-
export
|
|
18
|
+
export interface ColorConditionInput {
|
|
19
19
|
/** Name, code or hex (e.g. "sage green"). */
|
|
20
20
|
color?: string;
|
|
21
21
|
/** Must be the swatch's largest color. */
|
|
@@ -25,8 +25,8 @@ export type ColorConditionInput = {
|
|
|
25
25
|
share?: number;
|
|
26
26
|
/** Maximum share, e.g. an accent. */
|
|
27
27
|
shareMax?: number;
|
|
28
|
-
}
|
|
29
|
-
export
|
|
28
|
+
}
|
|
29
|
+
export interface FindVariantsByColorInput {
|
|
30
30
|
/** Brand slugs or names to filter to. */
|
|
31
31
|
brands?: string[];
|
|
32
32
|
/** One entry per color (exactly one for rerank). */
|
|
@@ -37,6 +37,7 @@ export type FindVariantsByColorInput = {
|
|
|
37
37
|
cursor?: string;
|
|
38
38
|
/** Palette only: targets from this image's colors, not `colors[]`. */
|
|
39
39
|
image?: ImageReferenceInput;
|
|
40
|
+
/** Variants a page, 1 to 24 (a larger value is a 400). Omitted: 16 for contains and palette, every given id for rerank. */
|
|
40
41
|
limit?: number;
|
|
41
42
|
mode: FindVariantsByColorMode;
|
|
42
43
|
/** Independent specification type or group keys, e.g. wallcovering or coatings; filters specification types, not source categories. */
|
|
@@ -45,8 +46,8 @@ export type FindVariantsByColorInput = {
|
|
|
45
46
|
targetVariantId?: string;
|
|
46
47
|
/** Ids to reorder by color (rerank). */
|
|
47
48
|
variantIds?: string[];
|
|
48
|
-
}
|
|
49
|
-
export
|
|
49
|
+
}
|
|
50
|
+
export interface ColorConditionReceipt {
|
|
50
51
|
/** CIEDE2000 difference to the assigned settled swatch. Never a probability. */
|
|
51
52
|
distance: number;
|
|
52
53
|
hex: string;
|
|
@@ -56,8 +57,8 @@ export type ColorConditionReceipt = {
|
|
|
56
57
|
proportion: number;
|
|
57
58
|
/** Requested share used for ColorVec retrieval, palette only; null otherwise. */
|
|
58
59
|
target: number | null;
|
|
59
|
-
}
|
|
60
|
-
export
|
|
60
|
+
}
|
|
61
|
+
export interface PaintCatalogVariant {
|
|
61
62
|
brand: string;
|
|
62
63
|
color: string | null;
|
|
63
64
|
imageUrl: string | null;
|
|
@@ -65,8 +66,8 @@ export type PaintCatalogVariant = {
|
|
|
65
66
|
product: string;
|
|
66
67
|
variantId: string;
|
|
67
68
|
variantName: string | null;
|
|
68
|
-
}
|
|
69
|
-
export
|
|
69
|
+
}
|
|
70
|
+
export interface ResolvedColor {
|
|
70
71
|
/** Other meanings of the same words, offered: ColorScope's color when a paint's exact name led. */
|
|
71
72
|
alternatives?: ColorAlternative[];
|
|
72
73
|
catalogVariant: PaintCatalogVariant | null;
|
|
@@ -76,21 +77,21 @@ export type ResolvedColor = {
|
|
|
76
77
|
kind: "point" | "region";
|
|
77
78
|
/** Image-extracted or stored target-variant swatch share; else null. */
|
|
78
79
|
share: number | null;
|
|
79
|
-
}
|
|
80
|
-
export
|
|
80
|
+
}
|
|
81
|
+
export interface ColorAlternative {
|
|
81
82
|
code?: string;
|
|
82
83
|
hex: string;
|
|
83
84
|
libraryId: string;
|
|
84
85
|
libraryName: string;
|
|
85
86
|
name: string;
|
|
86
87
|
query: string;
|
|
87
|
-
}
|
|
88
|
-
export
|
|
88
|
+
}
|
|
89
|
+
export interface UnresolvedColor {
|
|
89
90
|
alternatives: ColorAlternative[];
|
|
90
91
|
index: number;
|
|
91
92
|
input: string | null;
|
|
92
|
-
}
|
|
93
|
-
export
|
|
93
|
+
}
|
|
94
|
+
export interface ColorVariantMatch {
|
|
94
95
|
/** The trimmed source variant label; null when unknown or for a paint color sample. Separate from surface finish, color family and derived color names. */
|
|
95
96
|
variantLabel: string | null;
|
|
96
97
|
productType: {
|
|
@@ -116,8 +117,8 @@ export type ColorVariantMatch = {
|
|
|
116
117
|
productId: string;
|
|
117
118
|
variantId: string;
|
|
118
119
|
variantName: string;
|
|
119
|
-
}
|
|
120
|
-
export
|
|
120
|
+
}
|
|
121
|
+
export interface ColorPageInfo {
|
|
121
122
|
endCursor: string | null;
|
|
122
123
|
hasNextPage: boolean;
|
|
123
124
|
/**
|
|
@@ -128,15 +129,15 @@ export type ColorPageInfo = {
|
|
|
128
129
|
* the page where paging stops at the pool's 400 cap.
|
|
129
130
|
*/
|
|
130
131
|
poolTruncated: boolean;
|
|
131
|
-
}
|
|
132
|
-
|
|
132
|
+
}
|
|
133
|
+
interface ContainsOrPaletteResult {
|
|
133
134
|
/** Color-matched candidates dropped by `list_variants`' hard filters or eligibility. */
|
|
134
135
|
gatedOut: number;
|
|
135
136
|
matches: ColorVariantMatch[];
|
|
136
137
|
pageInfo: ColorPageInfo;
|
|
137
138
|
resolvedColors: ResolvedColor[];
|
|
138
139
|
unresolvedColors: UnresolvedColor[];
|
|
139
|
-
}
|
|
140
|
+
}
|
|
140
141
|
export type FindVariantsByColorContainsResult = ContainsOrPaletteResult & {
|
|
141
142
|
mode: "contains";
|
|
142
143
|
};
|
|
@@ -144,7 +145,7 @@ export type FindVariantsByColorPaletteResult = ContainsOrPaletteResult & {
|
|
|
144
145
|
mode: "palette";
|
|
145
146
|
};
|
|
146
147
|
/** `reference.candidates`/`reference.seed`'s shape — mirrors `compare-color-similarity.ts`'s own seed, unlike `matches[]` below. */
|
|
147
|
-
export
|
|
148
|
+
export interface ColorRankedSeed {
|
|
148
149
|
brand: string;
|
|
149
150
|
brandSlug: string;
|
|
150
151
|
color: string | null;
|
|
@@ -155,9 +156,9 @@ export type ColorRankedSeed = {
|
|
|
155
156
|
variantId: string;
|
|
156
157
|
/** The variant's own name — paint colorway names live here (label contract). */
|
|
157
158
|
variantName: string | null;
|
|
158
|
-
}
|
|
159
|
+
}
|
|
159
160
|
/** RERANK's own card — the same shape `ColorVariantMatch` above (`brandId`, `code`), plus its perceptual distance. */
|
|
160
|
-
export
|
|
161
|
+
export interface ColorRankMatch {
|
|
161
162
|
/** The trimmed source variant label; null when unknown or for a paint color sample. Separate from surface finish, color family and derived color names. */
|
|
162
163
|
variantLabel: string | null;
|
|
163
164
|
brand: string;
|
|
@@ -171,13 +172,13 @@ export type ColorRankMatch = {
|
|
|
171
172
|
productId: string;
|
|
172
173
|
variantId: string;
|
|
173
174
|
variantName: string | null;
|
|
174
|
-
}
|
|
175
|
-
export
|
|
175
|
+
}
|
|
176
|
+
export interface ResolvedColorReference {
|
|
176
177
|
hex: string;
|
|
177
178
|
name: string | null;
|
|
178
179
|
ref: string;
|
|
179
|
-
}
|
|
180
|
-
export
|
|
180
|
+
}
|
|
181
|
+
export interface CompareColorSimilarityReference {
|
|
181
182
|
/** Best-per-brand candidates when `resolution === "ambiguous"`; empty otherwise. */
|
|
182
183
|
candidates: ColorRankedSeed[];
|
|
183
184
|
/** The resolved color when the reference was a `color`, else null. */
|
|
@@ -197,8 +198,8 @@ export type CompareColorSimilarityReference = {
|
|
|
197
198
|
resolution: "resolved" | "ambiguous";
|
|
198
199
|
/** The resolved seed when the reference was a `material`/`variantId`, else null. */
|
|
199
200
|
seed: ColorRankedSeed | null;
|
|
200
|
-
}
|
|
201
|
-
export
|
|
201
|
+
}
|
|
202
|
+
export interface FindVariantsByColorRerankResult {
|
|
202
203
|
/** Present ONLY when the request narrowed it. ABSENT means the whole graph. */
|
|
203
204
|
searchCatalogSubset?: SearchCatalogSubsetReceipt;
|
|
204
205
|
/** Real variant ids outside `searchCatalogSubset` or the materials catalog. Present when a scope narrowed or any was excluded. */
|
|
@@ -212,6 +213,6 @@ export type FindVariantsByColorRerankResult = {
|
|
|
212
213
|
resolvedColors: ResolvedColor[];
|
|
213
214
|
/** Candidate ids that did not resolve to any variant. */
|
|
214
215
|
unresolved: string[];
|
|
215
|
-
}
|
|
216
|
+
}
|
|
216
217
|
export type FindVariantsByColorOutput = FindVariantsByColorContainsResult | FindVariantsByColorPaletteResult | FindVariantsByColorRerankResult;
|
|
217
218
|
export {};
|
|
@@ -12,14 +12,14 @@ import type { FilterGroups, VariantCard } from "./list-variants-types.js";
|
|
|
12
12
|
import type { SearchCatalogSubset } from "./search-catalog-subset-types.js";
|
|
13
13
|
export declare const FIND_VARIANTS_BY_VECTOR_MODES: readonly ["text", "image", "text_and_image"];
|
|
14
14
|
export type FindVariantsByVectorMode = (typeof FIND_VARIANTS_BY_VECTOR_MODES)[number];
|
|
15
|
-
export
|
|
15
|
+
export interface FindVariantsByVectorQuery {
|
|
16
16
|
/** One to six image references, each with exactly one field. Several are combined into one query, and every seed image's variant is left out. Only for image modes. Each image that has to be embedded spends one of the embed requests. */
|
|
17
17
|
images?: ImageReferenceInput[];
|
|
18
18
|
mode: FindVariantsByVectorMode;
|
|
19
19
|
/** Description, mood words included. Only for text modes. */
|
|
20
20
|
text?: string;
|
|
21
|
-
}
|
|
22
|
-
export
|
|
21
|
+
}
|
|
22
|
+
export interface FindVariantsByVectorInput {
|
|
23
23
|
/** Attribute or block ids to add. */
|
|
24
24
|
attributes?: string[];
|
|
25
25
|
/** Variant ids to leave out. A seed image's own variant is always left out. */
|
|
@@ -30,26 +30,26 @@ export type FindVariantsByVectorInput = {
|
|
|
30
30
|
query: FindVariantsByVectorQuery;
|
|
31
31
|
/** Only this corpus scope. Absent or all: every variant. */
|
|
32
32
|
searchCatalogSubset?: SearchCatalogSubset;
|
|
33
|
-
}
|
|
33
|
+
}
|
|
34
34
|
export type FindVariantsByVectorItem = Omit<VariantCard, "materialBankId"> & {
|
|
35
35
|
/** The variant's Material Bank SKU; null means none is recorded. Always present here, unlike `list_variants`' optional field. */
|
|
36
36
|
materialBankId: string | null;
|
|
37
37
|
/** Voyage cosine to the query. Ranks only; not a probability. */
|
|
38
38
|
similarity: number;
|
|
39
39
|
};
|
|
40
|
-
export
|
|
40
|
+
export interface FindVariantsByVectorReference {
|
|
41
41
|
id: string;
|
|
42
42
|
kind: "url" | "assetId" | "variantId" | "sourceId";
|
|
43
|
-
}
|
|
44
|
-
export
|
|
43
|
+
}
|
|
44
|
+
export interface FindVariantsByVectorScan {
|
|
45
45
|
/** True when no further candidates match; false means more may exist. */
|
|
46
46
|
exhausted: boolean;
|
|
47
47
|
read: number;
|
|
48
48
|
rejected: number;
|
|
49
49
|
/** How filters reached the vector search. Always "metadata": every filter runs inside the kNN. */
|
|
50
50
|
route: "lane" | "metadata" | "allowlist";
|
|
51
|
-
}
|
|
52
|
-
export
|
|
51
|
+
}
|
|
52
|
+
export interface FindVariantsByVectorTimings {
|
|
53
53
|
embedMs: number;
|
|
54
54
|
/** Time spent filtering outside the kNN. Always 0: filters run inside it. */
|
|
55
55
|
filterMs: number;
|
|
@@ -57,8 +57,8 @@ export type FindVariantsByVectorTimings = {
|
|
|
57
57
|
totalMs: number;
|
|
58
58
|
vectorMs: number;
|
|
59
59
|
verifyMs: number;
|
|
60
|
-
}
|
|
61
|
-
export
|
|
60
|
+
}
|
|
61
|
+
export interface FindVariantsByVectorOutput {
|
|
62
62
|
/** Explicit `{field: "variant", op: "in"}` filter ids that name a real variant outside the materials catalog — present only when at least one did. */
|
|
63
63
|
excludedBySearchCatalogSubset?: string[];
|
|
64
64
|
items: FindVariantsByVectorItem[];
|
|
@@ -71,6 +71,6 @@ export type FindVariantsByVectorOutput = {
|
|
|
71
71
|
timings: FindVariantsByVectorTimings;
|
|
72
72
|
/** Explicit `{field: "variant", op: "in"}` filter ids that named no eligible variant — present only when at least one did. */
|
|
73
73
|
unresolvedVariantIds?: string[];
|
|
74
|
-
/**
|
|
74
|
+
/** Filter fields no variant in scope states at all. Present only on an empty page, so its absence means the empty page is a genuine no-match. */
|
|
75
75
|
unstated?: string[];
|
|
76
|
-
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module get-variant-demand-types
|
|
3
|
+
* @description Hand-maintained mirror of `get_variant_demand`'s and
|
|
4
|
+
* `list_rising_variants`' wire shapes.
|
|
5
|
+
* The source of truth is `packages/demand/src/contract.ts`; this SDK has
|
|
6
|
+
* no runtime dependency on `@materialgraph/demand`, so the shapes are copied
|
|
7
|
+
* here.
|
|
8
|
+
*/
|
|
9
|
+
import type { OpenEnum } from "./types.js";
|
|
10
|
+
export interface GetVariantDemandInput {
|
|
11
|
+
/** 1 to 48 variant ids. */
|
|
12
|
+
variantIds: string[];
|
|
13
|
+
/** One Material Bank project type; omit for every project type together. */
|
|
14
|
+
projectType?: string;
|
|
15
|
+
}
|
|
16
|
+
export type DemandTrend = OpenEnum<"rising" | "steady" | "falling">;
|
|
17
|
+
export type VariantDemand = {
|
|
18
|
+
state: "measured";
|
|
19
|
+
variantId: string;
|
|
20
|
+
/** The category the percentile is ranked within. */
|
|
21
|
+
category: string;
|
|
22
|
+
/** Share of the category's variants sampled as much or less, 1 to 100. */
|
|
23
|
+
samplePercentile: number;
|
|
24
|
+
/** Null when the year before cannot be shown. */
|
|
25
|
+
trend: DemandTrend | null;
|
|
26
|
+
/** This year against the year before; 0.4 is 40% more. Null with `trend`. */
|
|
27
|
+
change: number | null;
|
|
28
|
+
}
|
|
29
|
+
/** Too few members sampled it to show, or nobody did. */
|
|
30
|
+
| {
|
|
31
|
+
state: "not_shown";
|
|
32
|
+
variantId: string;
|
|
33
|
+
} | {
|
|
34
|
+
state: "unknown_variant";
|
|
35
|
+
variantId: string;
|
|
36
|
+
};
|
|
37
|
+
export interface GetVariantDemandOutput {
|
|
38
|
+
/** Last day of the measured year, as an ISO date. */
|
|
39
|
+
asOf: string;
|
|
40
|
+
basis: "measured";
|
|
41
|
+
source: string;
|
|
42
|
+
/** One reading per requested id, in request order, duplicates kept. */
|
|
43
|
+
results: VariantDemand[];
|
|
44
|
+
}
|
|
45
|
+
export interface ListRisingVariantsInput {
|
|
46
|
+
/** A MaterialGraph category id, such as `wallcovering`. */
|
|
47
|
+
category: string;
|
|
48
|
+
/** Variants to return, at most 100. Default 20. */
|
|
49
|
+
limit?: number;
|
|
50
|
+
/** One Material Bank project type; omit for every project type together. */
|
|
51
|
+
projectType?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface RisingVariant {
|
|
54
|
+
variantId: string;
|
|
55
|
+
/** Share of the category's variants sampled as much or less, 1 to 100. */
|
|
56
|
+
samplePercentile: number;
|
|
57
|
+
trend: DemandTrend | null;
|
|
58
|
+
/** This year against the year before; 0.4 is 40% more. */
|
|
59
|
+
change: number | null;
|
|
60
|
+
}
|
|
61
|
+
export interface ListRisingVariantsOutput {
|
|
62
|
+
/** Last day of the measured year, as an ISO date. */
|
|
63
|
+
asOf: string;
|
|
64
|
+
basis: "measured";
|
|
65
|
+
category: string;
|
|
66
|
+
/** Largest change first. */
|
|
67
|
+
results: RisingVariant[];
|
|
68
|
+
source: string;
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/get-variant-types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import type { ListVariantsNotApplicable, ListVariantsSpecifications, SampleSubject, VariantObservations } from "./list-variants-types.js";
|
|
11
11
|
import type { VariantColorPalette } from "./material-block-types.js";
|
|
12
12
|
/** The detail to add under `specifications`; absent, the answer is the compact item alone. */
|
|
13
|
-
export
|
|
13
|
+
export interface GetVariantOptions {
|
|
14
14
|
/** Canonical attribute ids, e.g. `["nrc"]`. */
|
|
15
15
|
attributes?: readonly string[];
|
|
16
16
|
/** Canonical block ids, returned whole, e.g. `["acoustic"]`. */
|
|
@@ -19,12 +19,12 @@ export type GetVariantOptions = {
|
|
|
19
19
|
observations?: readonly string[];
|
|
20
20
|
/** Add `ifc`: the IFC 4.3 manufacturer property set and classification references. */
|
|
21
21
|
ifc?: boolean;
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
/**
|
|
24
24
|
* The variant as an IFC 4.3 type states it. Properties the record does not
|
|
25
25
|
* hold are left out, so an absent property is unknown.
|
|
26
26
|
*/
|
|
27
|
-
export
|
|
27
|
+
export interface GetVariantIfc {
|
|
28
28
|
propertySets: {
|
|
29
29
|
name: "Pset_ManufacturerTypeInformation";
|
|
30
30
|
properties: {
|
|
@@ -41,13 +41,13 @@ export type GetVariantIfc = {
|
|
|
41
41
|
name?: string;
|
|
42
42
|
edition?: string;
|
|
43
43
|
}[];
|
|
44
|
-
}
|
|
44
|
+
}
|
|
45
45
|
/**
|
|
46
46
|
* One variant: the compact identity, and `specifications` only for the
|
|
47
47
|
* attributes and blocks that were asked for. Only stated values appear there:
|
|
48
48
|
* an unknown value, and a block with none, is absent, never false or zero.
|
|
49
49
|
*/
|
|
50
|
-
export
|
|
50
|
+
export interface GetVariantOutput {
|
|
51
51
|
/** Whether this variant may appear in its Brand's catalog. Material-only lists also require Search Catalog membership. Reads by id include ineligible variants. */
|
|
52
52
|
eligible: boolean;
|
|
53
53
|
channels: string[];
|
|
@@ -59,7 +59,7 @@ export type GetVariantOutput = {
|
|
|
59
59
|
}[];
|
|
60
60
|
attributes: Record<string, {
|
|
61
61
|
value: unknown;
|
|
62
|
-
valueSource: "brand" | "material_bank" | "measured" | "manual" | null;
|
|
62
|
+
valueSource: "brand" | "material_bank" | "measured" | "manual" | "inferred" | null;
|
|
63
63
|
wording: string | null;
|
|
64
64
|
level: "variant" | "product" | "brand";
|
|
65
65
|
}>;
|
|
@@ -117,4 +117,4 @@ export type GetVariantOutput = {
|
|
|
117
117
|
};
|
|
118
118
|
url: string | null;
|
|
119
119
|
variantId: string;
|
|
120
|
-
}
|
|
120
|
+
}
|
package/http-transport.d.ts
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
import type { RateLimit } from "./errors.js";
|
|
2
|
+
import type { JsonValue } from "./json-value-types.js";
|
|
2
3
|
import type { JsonOperationId, OperationResponses } from "./operation-responses.js";
|
|
3
4
|
import type { SdkOperation } from "./operations.js";
|
|
4
5
|
type QueryValue = string | number | boolean | undefined | null | (string | number | boolean)[];
|
|
5
6
|
export type QueryParams = Record<string, QueryValue>;
|
|
6
|
-
export
|
|
7
|
+
export interface RequestOptions {
|
|
7
8
|
/** Required by state-changing operations that support safe retries. */
|
|
8
9
|
idempotencyKey?: string;
|
|
9
10
|
query?: QueryParams;
|
|
10
11
|
body?: unknown;
|
|
11
12
|
signal?: AbortSignal;
|
|
12
13
|
pathParams?: Readonly<Record<string, string>>;
|
|
13
|
-
}
|
|
14
|
+
}
|
|
14
15
|
/** A read, status-checked HTTP response with its parsed body. */
|
|
15
|
-
export
|
|
16
|
+
export interface SentResponse {
|
|
16
17
|
response: Response;
|
|
17
18
|
text: string;
|
|
18
|
-
parsed:
|
|
19
|
-
}
|
|
20
|
-
|
|
19
|
+
parsed: JsonValue | undefined;
|
|
20
|
+
}
|
|
21
|
+
interface SendInput {
|
|
21
22
|
method: string;
|
|
22
23
|
url: string;
|
|
23
24
|
headers: Record<string, string>;
|
|
24
25
|
/** The only bodies the SDK sends: a JSON string or a multipart `FormData`. */
|
|
25
26
|
body?: string | FormData;
|
|
26
27
|
signal?: AbortSignal;
|
|
27
|
-
}
|
|
28
|
-
export
|
|
28
|
+
}
|
|
29
|
+
export interface HttpTransportOptions {
|
|
29
30
|
apiKey: string;
|
|
30
31
|
baseUrl: string;
|
|
31
32
|
fetch: typeof fetch;
|
|
32
33
|
/** Deadline in milliseconds for each JSON or upload request. Not applied to streams. */
|
|
33
34
|
timeoutMs?: number;
|
|
34
|
-
}
|
|
35
|
+
}
|
|
35
36
|
export declare class HttpTransport {
|
|
36
37
|
#private;
|
|
37
38
|
readonly baseUrl: string;
|
|
@@ -40,7 +41,10 @@ export declare class HttpTransport {
|
|
|
40
41
|
constructor(options: HttpTransportOptions);
|
|
41
42
|
get lastRateLimit(): RateLimit | null;
|
|
42
43
|
/** The bearer + JSON `Accept` headers, plus any per-request additions. */
|
|
43
|
-
authHeaders(extra?: Record<string, string>):
|
|
44
|
+
authHeaders(extra?: Record<string, string>): {
|
|
45
|
+
Accept: string;
|
|
46
|
+
Authorization: string;
|
|
47
|
+
};
|
|
44
48
|
buildUrl(path: string, query?: QueryParams): string;
|
|
45
49
|
/**
|
|
46
50
|
* Send one request, capture rate limits, read the body, and map a non-2xx or
|
package/http-transport.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* failure surfaces as one {@link MaterialGraphError}.
|
|
7
7
|
*/
|
|
8
8
|
import { MaterialGraphError } from "./errors.js";
|
|
9
|
+
import { parseJson } from "./json.js";
|
|
9
10
|
import { operationPath } from "./operations.js";
|
|
10
11
|
import { parseOperationResponse } from "./parse-operation-response.js";
|
|
11
12
|
const parseNumberOrNull = (value) => {
|
|
@@ -106,11 +107,11 @@ export class HttpTransport {
|
|
|
106
107
|
signal,
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
|
-
catch (
|
|
110
|
+
catch (error) {
|
|
110
111
|
throw MaterialGraphError.fromTransport({
|
|
111
112
|
...metadata,
|
|
112
113
|
callerSignal: signal,
|
|
113
|
-
cause,
|
|
114
|
+
cause: error,
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
const rateLimit = parseRateLimit(response.headers);
|
|
@@ -119,17 +120,17 @@ export class HttpTransport {
|
|
|
119
120
|
try {
|
|
120
121
|
text = await response.text();
|
|
121
122
|
}
|
|
122
|
-
catch (
|
|
123
|
+
catch (error) {
|
|
123
124
|
throw MaterialGraphError.fromTransport({
|
|
124
125
|
...metadata,
|
|
125
126
|
callerSignal: signal,
|
|
126
|
-
cause,
|
|
127
|
+
cause: error,
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
130
|
let parsed;
|
|
130
131
|
if (text.length > 0) {
|
|
131
132
|
try {
|
|
132
|
-
parsed =
|
|
133
|
+
parsed = parseJson(text);
|
|
133
134
|
}
|
|
134
135
|
catch {
|
|
135
136
|
parsed = text;
|
|
@@ -152,15 +153,16 @@ export class HttpTransport {
|
|
|
152
153
|
async requestJson(sdkOperation, options = {}) {
|
|
153
154
|
const url = this.buildUrl(operationPath(sdkOperation, options.pathParams), options.query);
|
|
154
155
|
const hasBody = options.body !== undefined;
|
|
156
|
+
const extraHeaders = {};
|
|
157
|
+
if (hasBody) {
|
|
158
|
+
extraHeaders["Content-Type"] = "application/json";
|
|
159
|
+
}
|
|
160
|
+
if (options.idempotencyKey !== undefined && options.idempotencyKey !== "") {
|
|
161
|
+
extraHeaders["Idempotency-Key"] = options.idempotencyKey;
|
|
162
|
+
}
|
|
155
163
|
const { parsed } = await this.send({
|
|
156
164
|
body: hasBody ? JSON.stringify(options.body) : undefined,
|
|
157
|
-
headers: this.authHeaders(
|
|
158
|
-
...(hasBody ? { "Content-Type": "application/json" } : {}),
|
|
159
|
-
...(options.idempotencyKey !== undefined &&
|
|
160
|
-
options.idempotencyKey !== ""
|
|
161
|
-
? { "Idempotency-Key": options.idempotencyKey }
|
|
162
|
-
: {}),
|
|
163
|
-
}),
|
|
165
|
+
headers: this.authHeaders(extraHeaders),
|
|
164
166
|
method: sdkOperation.method,
|
|
165
167
|
signal: options.signal,
|
|
166
168
|
url,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* or an existing variant's own image. Exactly one field is set per call; the
|
|
7
7
|
* server refuses more than one.
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export interface ImageReferenceInput {
|
|
10
10
|
/** Catalog asset id. */
|
|
11
11
|
assetId?: string;
|
|
12
12
|
/** Upload id (`smf_...`) from source-material. */
|
|
@@ -15,4 +15,4 @@ export type ImageReferenceInput = {
|
|
|
15
15
|
url?: string;
|
|
16
16
|
/** Variant whose image to use. */
|
|
17
17
|
variantId?: string;
|
|
18
|
-
}
|
|
18
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ export type { MaterialGraphClientOptions } from "./client.js";
|
|
|
4
4
|
export type { FilterOp, FilterTermCondition, FilterNumericCondition, FilterPresenceCondition, FilterAnyFieldCondition, FilterCondition, FilterGroups, OptionalFilterGroups, OrderByEntry, ListVariantsInclude, ListVariantsCollapse, ColorRegion, ColorRangeCondition, ListVariantsInput, ListVariantsPreference, ListVariantsSpecifications, ListVariantsNotApplicable, SampleSizeObservation, VariantObservations, SampleSubject, ListVariantsItem, ListVariantsOutput, VariantCard, } from "./list-variants-types.js";
|
|
5
5
|
export type { ListVariantFacetsInput, VariantFacetValue, CategoricalVariantFacet, BooleanVariantFacet, NumericVariantFacet, VariantFacet, ListVariantFacetsOutput, } from "./list-variant-facets-types.js";
|
|
6
6
|
export type { SearchVariantsSelection, SearchVariantsInput, SearchVariantsUnderstood, SearchVariantsReading, SearchVariantsSuggestion, SearchVariantsChoice, SearchVariantsOutput, } from "./search-variants-types.js";
|
|
7
|
+
export type { Baseline, BaselineResult, BaselineSource, BaselineStrength, BaselineWayToMeet, CheckBaselinesInput, CheckBaselinesResult, ListBaselinesOptions, ListBaselinesResult, } from "./baseline-types.js";
|
|
7
8
|
export type { ListEnumValuesOptions, EnumValueMatch, EnumValueItem, ListEnumValuesResult, } from "./list-enum-values-types.js";
|
|
8
9
|
export type { GetVariantIfc, GetVariantOptions, GetVariantOutput, } from "./get-variant-types.js";
|
|
9
10
|
export type { ImageReferenceInput } from "./image-reference-types.js";
|
|
10
11
|
export type { SampledTogetherProjectType, FindSampledTogetherInput, FindSampledTogetherRow, FindSampledTogetherOutput, } from "./find-sampled-together-types.js";
|
|
12
|
+
export type { GetVariantDemandInput, GetVariantDemandOutput, DemandTrend, VariantDemand, ListRisingVariantsInput, ListRisingVariantsOutput, RisingVariant, } from "./get-variant-demand-types.js";
|
|
11
13
|
export type { ListSampledTogetherPairsInput, ListSampledTogetherPairsOutput, SampledTogetherPair, } from "./list-sampled-together-pairs-types.js";
|
|
12
14
|
export type { FindVariantsByColorMode, ColorConditionInput, FindVariantsByColorInput, ColorConditionReceipt, PaintCatalogVariant, ResolvedColor, ColorAlternative, UnresolvedColor, ColorVariantMatch, ColorPageInfo, FindVariantsByColorContainsResult, FindVariantsByColorPaletteResult, ColorRankedSeed, ColorRankMatch, ResolvedColorReference, CompareColorSimilarityReference, FindVariantsByColorRerankResult, FindVariantsByColorOutput, } from "./find-variants-by-color-types.js";
|
|
13
15
|
export { FIND_VARIANTS_BY_VECTOR_MODES } from "./find-variants-by-vector-types.js";
|
|
@@ -18,7 +20,7 @@ export type { OpaqueId, VariantId, ProductId, BatchId, SourceFileId, ProjectId,
|
|
|
18
20
|
export type { FileInput, UploadSourceMaterialInput, SourceMaterialReceiptFile, SourceMaterialBatchReceipt, } from "./source-material-types.js";
|
|
19
21
|
export { MATERIALGRAPH_PROBLEM_EXTENSIONS, MaterialGraphError, } from "./errors.js";
|
|
20
22
|
export type { MaterialGraphErrorInit, MaterialGraphErrorKind, MaterialGraphRequestMetadata, ProblemDetail, RateLimit, SanitizedErrorValue, SanitizedIssue, SimpleErrorBody, } from "./errors.js";
|
|
21
|
-
export type { OpenEnum, JsonValue, OklabTriple, MaterialColor, ImageSource, MaterialAvailability, MaterialTile,
|
|
23
|
+
export type { OpenEnum, JsonValue, OklabTriple, MaterialColor, ImageSource, MaterialAvailability, MaterialTile, CompanionDemand, ProjectTypeShare, CospecPairing, ColorPairing, PairingOrderMode, PairingRanking, PairingOrdering, PairingItem, PairingsResponse, AttributeMatch, AttributeListItem, OutsideScopeAttribute, ListAttributesResult, WhoamiResponse, PairingsOptions, ListAttributesOptions, ExtractedPalette, ExtractPaletteResponse, ExtractPaletteInput, ResolveValueCandidate, ValueResolution, ResolveColorOptions, ResolveColorCatalogVariant, ResolveColorVariant, ResolveColorResponse, BySpecVerdictState, BySpecVerdictCell, BySpecVerdict, MaterialVerdict, BySpecUnresolvedCriterion, } from "./types.js";
|
|
22
24
|
export type { ResolveVariantInput, ResolveVariantSubject, ResolveVariantEvidence, ResolveVariantReceipt, ResolveVariantUnresolvedReason, ResolveVariantOutput, } from "./resolve-variant-types.js";
|
|
23
25
|
export { CategoriesClient } from "./categories-client.js";
|
|
24
26
|
export type { CategoryRef, CategoryKind, CategoryMatch, CategoryItem, CategoriesPageInfo, CategoriesListInput, CategoriesListResult, CategoryConcept, CategoryProductCategory, CategoriesGetResult, } from "./category-types.js";
|
package/json.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { JsonValue } from "./json-value-types.js";
|
|
2
|
+
/** A JSON object: string keys, JSON values. */
|
|
3
|
+
export interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
export type JsonKind = "array" | "boolean" | "null" | "number" | "object" | "string" | "undefined";
|
|
7
|
+
/** What a parsed JSON value is, or `undefined` for a key an object lacks. */
|
|
8
|
+
export declare const jsonKind: (value: JsonValue | undefined) => JsonKind;
|
|
9
|
+
export declare const isJsonObject: (value: JsonValue | undefined) => value is JsonObject;
|
|
10
|
+
export declare const isJsonString: (value: JsonValue | undefined) => value is string;
|
|
11
|
+
export declare const isJsonNumber: (value: JsonValue | undefined) => value is number;
|
|
12
|
+
/** Parses JSON text; throws on text that is not JSON. */
|
|
13
|
+
export declare const parseJson: (text: string) => JsonValue;
|
|
14
|
+
/**
|
|
15
|
+
* Reads a value of unknown origin as the JSON it would serialize to. A value
|
|
16
|
+
* JSON cannot represent, such as a `bigint`, reads as absent.
|
|
17
|
+
*/
|
|
18
|
+
export declare const toJsonValue: (value: unknown) => JsonValue | undefined;
|
package/json.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** What a parsed JSON value is, or `undefined` for a key an object lacks. */
|
|
2
|
+
export const jsonKind = (value) => {
|
|
3
|
+
if (value === null) {
|
|
4
|
+
return "null";
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
return "array";
|
|
8
|
+
}
|
|
9
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- This is the one place a parsed JSON value is classified; every other check calls it.
|
|
10
|
+
const kind = typeof value;
|
|
11
|
+
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
12
|
+
return kind;
|
|
13
|
+
}
|
|
14
|
+
return kind === "undefined" ? "undefined" : "object";
|
|
15
|
+
};
|
|
16
|
+
export const isJsonObject = (value) => jsonKind(value) === "object";
|
|
17
|
+
export const isJsonString = (value) => jsonKind(value) === "string";
|
|
18
|
+
export const isJsonNumber = (value) => jsonKind(value) === "number";
|
|
19
|
+
/** Parses JSON text; throws on text that is not JSON. */
|
|
20
|
+
export const parseJson = (text) =>
|
|
21
|
+
// oxlint-disable-next-line typescript/no-unsafe-return -- `JSON.parse` returns exactly the values `JsonValue` names.
|
|
22
|
+
JSON.parse(text);
|
|
23
|
+
/**
|
|
24
|
+
* Reads a value of unknown origin as the JSON it would serialize to. A value
|
|
25
|
+
* JSON cannot represent, such as a `bigint`, reads as absent.
|
|
26
|
+
*/
|
|
27
|
+
// oxlint-disable-next-line anti-slop/no-unknown-parameters -- A published caller may pass any body; this is where it becomes JSON.
|
|
28
|
+
export const toJsonValue = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
const text = JSON.stringify(value);
|
|
31
|
+
return text === undefined ? undefined : parseJson(text);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { OpenEnum } from "./types.js";
|
|
10
10
|
/** Options for `listEnumValues()` (GET `/api/v1/catalog/enum-values`). */
|
|
11
|
-
export
|
|
11
|
+
export interface ListEnumValuesOptions {
|
|
12
12
|
/**
|
|
13
13
|
* A value dictionary id, from a `listAttributes()` item's `dictionaryId`.
|
|
14
14
|
* Required without a `query`; with a `query`, omit it to search every
|
|
@@ -21,9 +21,9 @@ export type ListEnumValuesOptions = {
|
|
|
21
21
|
limit?: number;
|
|
22
22
|
/** `pageInfo.endCursor` from the previous page, with the same query and dictionary. */
|
|
23
23
|
cursor?: string;
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
/** How an item was found. A distance or similarity compares only within one method. */
|
|
26
|
-
export
|
|
26
|
+
export interface EnumValueMatch {
|
|
27
27
|
method: OpenEnum<"exact" | "alias" | "fuzzy" | "vector">;
|
|
28
28
|
/** The id, label or alias that matched, or null for a match by meaning. */
|
|
29
29
|
matchedText: string | null;
|
|
@@ -33,9 +33,9 @@ export type EnumValueMatch = {
|
|
|
33
33
|
resolvedFrom?: string;
|
|
34
34
|
/** Cosine similarity, 1 best. */
|
|
35
35
|
similarity?: number;
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
37
|
/** One allowed value of a dictionary. */
|
|
38
|
-
export
|
|
38
|
+
export interface EnumValueItem {
|
|
39
39
|
/** The attributes this value can filter `listVariants()` on; empty when it cannot be filtered on. */
|
|
40
40
|
attributeIds: string[];
|
|
41
41
|
/** The taxonomy's definition when the value resolves to a canonical concept, otherwise null. */
|
|
@@ -46,8 +46,8 @@ export type EnumValueItem = {
|
|
|
46
46
|
match?: EnumValueMatch;
|
|
47
47
|
/** The bare term id `listVariants()` accepts for any of `attributeIds`. */
|
|
48
48
|
valueId: string;
|
|
49
|
-
}
|
|
50
|
-
export
|
|
49
|
+
}
|
|
50
|
+
export interface ListEnumValuesResult {
|
|
51
51
|
/** The dictionary the page was read from; null when a query searched every dictionary. */
|
|
52
52
|
dictionaryId: string | null;
|
|
53
53
|
items: EnumValueItem[];
|
|
@@ -55,4 +55,4 @@ export type ListEnumValuesResult = {
|
|
|
55
55
|
endCursor: string | null;
|
|
56
56
|
hasNextPage: boolean;
|
|
57
57
|
};
|
|
58
|
-
}
|
|
58
|
+
}
|