@salesforce/b2c-tooling-sdk 0.0.8 → 0.1.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/dist/cjs/clients/index.d.ts +3 -0
- package/dist/cjs/clients/index.js +2 -0
- package/dist/cjs/clients/index.js.map +1 -1
- package/dist/cjs/clients/middleware-registry.d.ts +1 -1
- package/dist/cjs/clients/scapi-schemas.d.ts +132 -0
- package/dist/cjs/clients/scapi-schemas.generated.d.ts +328 -0
- package/dist/cjs/clients/scapi-schemas.generated.js +6 -0
- package/dist/cjs/clients/scapi-schemas.generated.js.map +1 -0
- package/dist/cjs/clients/scapi-schemas.js +95 -0
- package/dist/cjs/clients/scapi-schemas.js.map +1 -0
- package/dist/cjs/operations/scapi-schemas/collapse.d.ts +150 -0
- package/dist/cjs/operations/scapi-schemas/collapse.js +180 -0
- package/dist/cjs/operations/scapi-schemas/collapse.js.map +1 -0
- package/dist/cjs/operations/scapi-schemas/index.d.ts +53 -0
- package/dist/cjs/operations/scapi-schemas/index.js +59 -0
- package/dist/cjs/operations/scapi-schemas/index.js.map +1 -0
- package/dist/esm/clients/index.d.ts +3 -0
- package/dist/esm/clients/index.js +2 -0
- package/dist/esm/clients/index.js.map +1 -1
- package/dist/esm/clients/middleware-registry.d.ts +1 -1
- package/dist/esm/clients/scapi-schemas.d.ts +132 -0
- package/dist/esm/clients/scapi-schemas.generated.d.ts +328 -0
- package/dist/esm/clients/scapi-schemas.generated.js +6 -0
- package/dist/esm/clients/scapi-schemas.generated.js.map +1 -0
- package/dist/esm/clients/scapi-schemas.js +95 -0
- package/dist/esm/clients/scapi-schemas.js.map +1 -0
- package/dist/esm/operations/scapi-schemas/collapse.d.ts +150 -0
- package/dist/esm/operations/scapi-schemas/collapse.js +180 -0
- package/dist/esm/operations/scapi-schemas/collapse.js.map +1 -0
- package/dist/esm/operations/scapi-schemas/index.d.ts +53 -0
- package/dist/esm/operations/scapi-schemas/index.js +59 -0
- package/dist/esm/operations/scapi-schemas/index.js.map +1 -0
- package/package.json +13 -2
- package/specs/scapi-schemas-v1.yaml +341 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, Salesforce, Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2
|
|
4
|
+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
*/
|
|
6
|
+
/** HTTP methods that can appear in OpenAPI paths */
|
|
7
|
+
const HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'];
|
|
8
|
+
/**
|
|
9
|
+
* Collapses an OpenAPI schema for context-efficient representation.
|
|
10
|
+
*
|
|
11
|
+
* This function implements a three-tier disclosure model:
|
|
12
|
+
*
|
|
13
|
+
* 1. **No options provided (default):**
|
|
14
|
+
* - Paths: `{"/products": ["get", "post"]}` (method names only)
|
|
15
|
+
* - Schemas: `{"Product": {}}` (keys only)
|
|
16
|
+
* - Examples: `{"ProductExample": {}}` (keys only)
|
|
17
|
+
*
|
|
18
|
+
* 2. **Selective expansion:**
|
|
19
|
+
* - Only specified paths/schemas/examples are fully expanded
|
|
20
|
+
* - Everything else remains collapsed
|
|
21
|
+
*
|
|
22
|
+
* Non-collapsible sections (info, servers, security, tags, etc.) are preserved as-is.
|
|
23
|
+
*
|
|
24
|
+
* @param schema - The OpenAPI schema to collapse
|
|
25
|
+
* @param options - Options controlling what to expand
|
|
26
|
+
* @returns The collapsed schema
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Collapse everything (default behavior)
|
|
30
|
+
* const collapsed = collapseOpenApiSchema(fullSchema);
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Expand only /products path and Product schema
|
|
34
|
+
* const collapsed = collapseOpenApiSchema(fullSchema, {
|
|
35
|
+
* expandPaths: ['/products'],
|
|
36
|
+
* expandSchemas: ['Product']
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
39
|
+
export function collapseOpenApiSchema(schema, options = {}) {
|
|
40
|
+
const { expandPaths = [], expandSchemas = [], expandExamples = [] } = options;
|
|
41
|
+
// Start with a shallow copy
|
|
42
|
+
const result = { ...schema };
|
|
43
|
+
// Collapse paths
|
|
44
|
+
if (schema.paths) {
|
|
45
|
+
result.paths = collapsePaths(schema.paths, expandPaths);
|
|
46
|
+
}
|
|
47
|
+
// Collapse components
|
|
48
|
+
if (schema.components) {
|
|
49
|
+
result.components = {
|
|
50
|
+
...schema.components,
|
|
51
|
+
};
|
|
52
|
+
if (schema.components.schemas) {
|
|
53
|
+
result.components.schemas = collapseSchemas(schema.components.schemas, expandSchemas);
|
|
54
|
+
}
|
|
55
|
+
if (schema.components.examples) {
|
|
56
|
+
result.components.examples = collapseExamples(schema.components.examples, expandExamples);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Collapses path items to show only HTTP method names.
|
|
63
|
+
*
|
|
64
|
+
* @param paths - The paths object from an OpenAPI schema
|
|
65
|
+
* @param expandPaths - Paths to keep fully expanded
|
|
66
|
+
* @returns Collapsed paths object
|
|
67
|
+
*/
|
|
68
|
+
function collapsePaths(paths, expandPaths) {
|
|
69
|
+
const result = {};
|
|
70
|
+
const expandSet = new Set(expandPaths);
|
|
71
|
+
for (const [pathKey, pathItem] of Object.entries(paths)) {
|
|
72
|
+
if (expandSet.has(pathKey)) {
|
|
73
|
+
// Keep full path item for expanded paths
|
|
74
|
+
result[pathKey] = pathItem;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Collapse to method names only
|
|
78
|
+
const methods = Object.keys(pathItem).filter((key) => HTTP_METHODS.includes(key));
|
|
79
|
+
result[pathKey] = methods;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Collapses schemas to show only keys with empty objects.
|
|
86
|
+
*
|
|
87
|
+
* @param schemas - The schemas object from components
|
|
88
|
+
* @param expandSchemas - Schema names to keep fully expanded
|
|
89
|
+
* @returns Collapsed schemas object
|
|
90
|
+
*/
|
|
91
|
+
function collapseSchemas(schemas, expandSchemas) {
|
|
92
|
+
const result = {};
|
|
93
|
+
const expandSet = new Set(expandSchemas);
|
|
94
|
+
for (const [schemaName, schemaValue] of Object.entries(schemas)) {
|
|
95
|
+
if (expandSet.has(schemaName)) {
|
|
96
|
+
// Keep full schema for expanded schemas
|
|
97
|
+
result[schemaName] = schemaValue;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Collapse to empty object
|
|
101
|
+
result[schemaName] = {};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Collapses examples to show only keys with empty objects.
|
|
108
|
+
*
|
|
109
|
+
* @param examples - The examples object from components
|
|
110
|
+
* @param expandExamples - Example names to keep fully expanded
|
|
111
|
+
* @returns Collapsed examples object
|
|
112
|
+
*/
|
|
113
|
+
function collapseExamples(examples, expandExamples) {
|
|
114
|
+
const result = {};
|
|
115
|
+
const expandSet = new Set(expandExamples);
|
|
116
|
+
for (const [exampleName, exampleValue] of Object.entries(examples)) {
|
|
117
|
+
if (expandSet.has(exampleName)) {
|
|
118
|
+
// Keep full example for expanded examples
|
|
119
|
+
result[exampleName] = exampleValue;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// Collapse to empty object
|
|
123
|
+
result[exampleName] = {};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Checks if a schema has been collapsed (i.e., is in outline form).
|
|
130
|
+
*
|
|
131
|
+
* @param schema - The schema to check
|
|
132
|
+
* @returns true if paths are collapsed (arrays) or schemas are empty objects
|
|
133
|
+
*/
|
|
134
|
+
export function isCollapsedSchema(schema) {
|
|
135
|
+
// Check if any path is collapsed (array of methods instead of full path item)
|
|
136
|
+
if (schema.paths) {
|
|
137
|
+
for (const pathItem of Object.values(schema.paths)) {
|
|
138
|
+
if (Array.isArray(pathItem)) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Check if any schema is collapsed (empty object)
|
|
144
|
+
if (schema.components?.schemas) {
|
|
145
|
+
for (const schemaValue of Object.values(schema.components.schemas)) {
|
|
146
|
+
if (typeof schemaValue === 'object' && schemaValue !== null && Object.keys(schemaValue).length === 0) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the list of available path keys from a schema.
|
|
155
|
+
*
|
|
156
|
+
* @param schema - The OpenAPI schema
|
|
157
|
+
* @returns Array of path keys (e.g., ["/products", "/orders"])
|
|
158
|
+
*/
|
|
159
|
+
export function getPathKeys(schema) {
|
|
160
|
+
return schema.paths ? Object.keys(schema.paths) : [];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets the list of available schema names from a schema.
|
|
164
|
+
*
|
|
165
|
+
* @param schema - The OpenAPI schema
|
|
166
|
+
* @returns Array of schema names (e.g., ["Product", "Order"])
|
|
167
|
+
*/
|
|
168
|
+
export function getSchemaNames(schema) {
|
|
169
|
+
return schema.components?.schemas ? Object.keys(schema.components.schemas) : [];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Gets the list of available example names from a schema.
|
|
173
|
+
*
|
|
174
|
+
* @param schema - The OpenAPI schema
|
|
175
|
+
* @returns Array of example names
|
|
176
|
+
*/
|
|
177
|
+
export function getExampleNames(schema) {
|
|
178
|
+
return schema.components?.examples ? Object.keys(schema.components.examples) : [];
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=collapse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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ACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmD;IAC7E,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAmD;IAChF,OAAO,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAClF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAmD;IACjF,OAAO,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SCAPI Schemas operations for B2C Commerce.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for working with SCAPI OpenAPI schemas, including
|
|
5
|
+
* collapsing large schemas for context-efficient representation in
|
|
6
|
+
* agentic/LLM scenarios.
|
|
7
|
+
*
|
|
8
|
+
* ## Schema Collapsing
|
|
9
|
+
*
|
|
10
|
+
* Use {@link collapseOpenApiSchema} to reduce the size of large OpenAPI schemas
|
|
11
|
+
* while preserving structure for discovery:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { collapseOpenApiSchema } from '@salesforce/b2c-tooling-sdk/operations/scapi-schemas';
|
|
15
|
+
*
|
|
16
|
+
* // Collapse to outline form (default)
|
|
17
|
+
* const collapsed = collapseOpenApiSchema(fullSchema);
|
|
18
|
+
* // Result: paths show only ["get", "post"], schemas show only {}
|
|
19
|
+
*
|
|
20
|
+
* // Selectively expand specific items
|
|
21
|
+
* const collapsed = collapseOpenApiSchema(fullSchema, {
|
|
22
|
+
* expandPaths: ['/products/search'],
|
|
23
|
+
* expandSchemas: ['Product', 'SearchResult']
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ## Utility Functions
|
|
28
|
+
*
|
|
29
|
+
* Helper functions for inspecting schemas:
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import {
|
|
33
|
+
* getPathKeys,
|
|
34
|
+
* getSchemaNames,
|
|
35
|
+
* isCollapsedSchema
|
|
36
|
+
* } from '@salesforce/b2c-tooling-sdk/operations/scapi-schemas';
|
|
37
|
+
*
|
|
38
|
+
* // Get available paths
|
|
39
|
+
* const paths = getPathKeys(schema); // ["/products", "/orders", ...]
|
|
40
|
+
*
|
|
41
|
+
* // Get available schemas
|
|
42
|
+
* const schemas = getSchemaNames(schema); // ["Product", "Order", ...]
|
|
43
|
+
*
|
|
44
|
+
* // Check if schema is collapsed
|
|
45
|
+
* if (isCollapsedSchema(schema)) {
|
|
46
|
+
* console.log('Schema is in collapsed form');
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @module operations/scapi-schemas
|
|
51
|
+
*/
|
|
52
|
+
export { collapseOpenApiSchema, isCollapsedSchema, getPathKeys, getSchemaNames, getExampleNames } from './collapse.js';
|
|
53
|
+
export type { SchemaCollapseOptions, OpenApiSchemaInput, CollapsedOpenApiSchema, CollapsedPath } from './collapse.js';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, Salesforce, Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2
|
|
4
|
+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* SCAPI Schemas operations for B2C Commerce.
|
|
8
|
+
*
|
|
9
|
+
* Provides utilities for working with SCAPI OpenAPI schemas, including
|
|
10
|
+
* collapsing large schemas for context-efficient representation in
|
|
11
|
+
* agentic/LLM scenarios.
|
|
12
|
+
*
|
|
13
|
+
* ## Schema Collapsing
|
|
14
|
+
*
|
|
15
|
+
* Use {@link collapseOpenApiSchema} to reduce the size of large OpenAPI schemas
|
|
16
|
+
* while preserving structure for discovery:
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { collapseOpenApiSchema } from '@salesforce/b2c-tooling-sdk/operations/scapi-schemas';
|
|
20
|
+
*
|
|
21
|
+
* // Collapse to outline form (default)
|
|
22
|
+
* const collapsed = collapseOpenApiSchema(fullSchema);
|
|
23
|
+
* // Result: paths show only ["get", "post"], schemas show only {}
|
|
24
|
+
*
|
|
25
|
+
* // Selectively expand specific items
|
|
26
|
+
* const collapsed = collapseOpenApiSchema(fullSchema, {
|
|
27
|
+
* expandPaths: ['/products/search'],
|
|
28
|
+
* expandSchemas: ['Product', 'SearchResult']
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* ## Utility Functions
|
|
33
|
+
*
|
|
34
|
+
* Helper functions for inspecting schemas:
|
|
35
|
+
*
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import {
|
|
38
|
+
* getPathKeys,
|
|
39
|
+
* getSchemaNames,
|
|
40
|
+
* isCollapsedSchema
|
|
41
|
+
* } from '@salesforce/b2c-tooling-sdk/operations/scapi-schemas';
|
|
42
|
+
*
|
|
43
|
+
* // Get available paths
|
|
44
|
+
* const paths = getPathKeys(schema); // ["/products", "/orders", ...]
|
|
45
|
+
*
|
|
46
|
+
* // Get available schemas
|
|
47
|
+
* const schemas = getSchemaNames(schema); // ["Product", "Order", ...]
|
|
48
|
+
*
|
|
49
|
+
* // Check if schema is collapsed
|
|
50
|
+
* if (isCollapsedSchema(schema)) {
|
|
51
|
+
* console.log('Schema is in collapsed form');
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @module operations/scapi-schemas
|
|
56
|
+
*/
|
|
57
|
+
// Collapse utilities
|
|
58
|
+
export { collapseOpenApiSchema, isCollapsedSchema, getPathKeys, getSchemaNames, getExampleNames } from './collapse.js';
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/operations/scapi-schemas/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,qBAAqB;AACrB,OAAO,EAAC,qBAAqB,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAC,MAAM,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/b2c-tooling-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Core tooling library for Salesforce Commerce Cloud B2C CLI",
|
|
5
5
|
"author": "Charles Lavery",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -123,6 +123,17 @@
|
|
|
123
123
|
"default": "./dist/cjs/operations/docs/index.js"
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
|
+
"./operations/scapi-schemas": {
|
|
127
|
+
"development": "./src/operations/scapi-schemas/index.ts",
|
|
128
|
+
"import": {
|
|
129
|
+
"types": "./dist/esm/operations/scapi-schemas/index.d.ts",
|
|
130
|
+
"default": "./dist/esm/operations/scapi-schemas/index.js"
|
|
131
|
+
},
|
|
132
|
+
"require": {
|
|
133
|
+
"types": "./dist/cjs/operations/scapi-schemas/index.d.ts",
|
|
134
|
+
"default": "./dist/cjs/operations/scapi-schemas/index.js"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
126
137
|
"./cli": {
|
|
127
138
|
"development": "./src/cli/index.ts",
|
|
128
139
|
"import": {
|
|
@@ -253,7 +264,7 @@
|
|
|
253
264
|
"xml2js": "^0.6.2"
|
|
254
265
|
},
|
|
255
266
|
"scripts": {
|
|
256
|
-
"generate:types": "openapi-typescript specs/data-api.json -o src/clients/ocapi.generated.ts && openapi-typescript specs/slas-admin-v1.yaml -o src/clients/slas-admin.generated.ts && openapi-typescript specs/ods-api-v1.json -o src/clients/ods.generated.ts && openapi-typescript specs/mrt-api-v1.json -o src/clients/mrt.generated.ts && openapi-typescript specs/custom-apis-v1.yaml -o src/clients/custom-apis.generated.ts",
|
|
267
|
+
"generate:types": "openapi-typescript specs/data-api.json -o src/clients/ocapi.generated.ts && openapi-typescript specs/slas-admin-v1.yaml -o src/clients/slas-admin.generated.ts && openapi-typescript specs/ods-api-v1.json -o src/clients/ods.generated.ts && openapi-typescript specs/mrt-api-v1.json -o src/clients/mrt.generated.ts && openapi-typescript specs/custom-apis-v1.yaml -o src/clients/custom-apis.generated.ts && openapi-typescript specs/scapi-schemas-v1.yaml -o src/clients/scapi-schemas.generated.ts",
|
|
257
268
|
"build": "pnpm run generate:types && pnpm run build:esm && pnpm run build:cjs",
|
|
258
269
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
259
270
|
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
openapi: 3.0.3
|
|
2
|
+
info:
|
|
3
|
+
x-api-type: Admin
|
|
4
|
+
x-api-family: DX
|
|
5
|
+
title: SCAPI Schemas
|
|
6
|
+
version: 1.0.0
|
|
7
|
+
description: |-
|
|
8
|
+
[Download API specification](https://developer.salesforce.com/static/commercecloud/commerce-api/scapi-schemas/scapi-schemas-oas-v1-public.yaml)
|
|
9
|
+
|
|
10
|
+
# API Overview
|
|
11
|
+
|
|
12
|
+
The SCAPI Schemas API provides access to OpenAPI schema definitions for Salesforce Commerce APIs (SCAPI). This API enables discovery and cataloging of available SCAPI endpoints, schema validation and code generation, version management for migration planning, and integration of schema access into development workflows including CI/CD pipelines and testing automation.
|
|
13
|
+
|
|
14
|
+
## Authentication & Authorization
|
|
15
|
+
|
|
16
|
+
The SCAPI Schemas API requires valid authentication and authorization. It uses an Account Manager OAuth 2.0 bearer token for authentication. The necessary scope for accessing the API is:
|
|
17
|
+
|
|
18
|
+
* `sfcc.scapi-schemas`: Provides read-only access to schema definitions.
|
|
19
|
+
|
|
20
|
+
Access is intended for admin users only.
|
|
21
|
+
|
|
22
|
+
## Use Cases
|
|
23
|
+
|
|
24
|
+
### Schema Discovery
|
|
25
|
+
|
|
26
|
+
Developers can use this API to discover available SCAPI schemas, filter by API family (e.g., shopper, admin), and retrieve detailed OpenAPI specifications for code generation or documentation purposes.
|
|
27
|
+
|
|
28
|
+
### Custom Property Expansion
|
|
29
|
+
|
|
30
|
+
When retrieving a schema, developers can request expansion of custom properties to see tenant-specific customizations applied to standard SCAPI schemas.
|
|
31
|
+
servers:
|
|
32
|
+
- url: https://{shortCode}.api.commercecloud.salesforce.com/dx/scapi-schemas/v1
|
|
33
|
+
variables:
|
|
34
|
+
shortCode:
|
|
35
|
+
default: shortCode
|
|
36
|
+
paths:
|
|
37
|
+
/organizations/{organizationId}/schemas:
|
|
38
|
+
get:
|
|
39
|
+
summary: Get a list of available SCAPI schemas.
|
|
40
|
+
description: List available SCAPI schema definitions with optional filtering by API family, name, version, or status.
|
|
41
|
+
operationId: getSchemas
|
|
42
|
+
parameters:
|
|
43
|
+
- $ref: '#/components/parameters/organizationId'
|
|
44
|
+
- $ref: '#/components/parameters/apiFamily'
|
|
45
|
+
- $ref: '#/components/parameters/apiName'
|
|
46
|
+
- $ref: '#/components/parameters/apiVersion'
|
|
47
|
+
- $ref: '#/components/parameters/status'
|
|
48
|
+
responses:
|
|
49
|
+
'200':
|
|
50
|
+
description: Successful operation
|
|
51
|
+
content:
|
|
52
|
+
application/json:
|
|
53
|
+
schema:
|
|
54
|
+
$ref: '#/components/schemas/SchemaListResult'
|
|
55
|
+
'400':
|
|
56
|
+
description: Invalid or malformed filter parameter
|
|
57
|
+
content:
|
|
58
|
+
application/problem+json:
|
|
59
|
+
schema:
|
|
60
|
+
$ref: '#/components/schemas/ErrorResponse'
|
|
61
|
+
'401':
|
|
62
|
+
description: Unauthorized - invalid or missing authentication
|
|
63
|
+
content:
|
|
64
|
+
application/problem+json:
|
|
65
|
+
schema:
|
|
66
|
+
$ref: '#/components/schemas/ErrorResponse'
|
|
67
|
+
'403':
|
|
68
|
+
description: Forbidden - insufficient permissions
|
|
69
|
+
content:
|
|
70
|
+
application/problem+json:
|
|
71
|
+
schema:
|
|
72
|
+
$ref: '#/components/schemas/ErrorResponse'
|
|
73
|
+
security:
|
|
74
|
+
- AmOAuth2:
|
|
75
|
+
- sfcc.scapi-schemas
|
|
76
|
+
/organizations/{organizationId}/schemas/{apiFamily}/{apiName}/{apiVersion}:
|
|
77
|
+
get:
|
|
78
|
+
summary: Get a specific SCAPI schema.
|
|
79
|
+
description: Retrieve the detailed OpenAPI schema specification for a specific SCAPI API.
|
|
80
|
+
operationId: getSchema
|
|
81
|
+
parameters:
|
|
82
|
+
- $ref: '#/components/parameters/organizationId'
|
|
83
|
+
- $ref: '#/components/parameters/apiFamilyPath'
|
|
84
|
+
- $ref: '#/components/parameters/apiNamePath'
|
|
85
|
+
- $ref: '#/components/parameters/apiVersionPath'
|
|
86
|
+
- $ref: '#/components/parameters/expand'
|
|
87
|
+
responses:
|
|
88
|
+
'200':
|
|
89
|
+
description: Successful operation - returns OpenAPI schema
|
|
90
|
+
content:
|
|
91
|
+
application/json:
|
|
92
|
+
schema:
|
|
93
|
+
$ref: '#/components/schemas/OpenApiSchema'
|
|
94
|
+
'400':
|
|
95
|
+
description: Invalid parameter value
|
|
96
|
+
content:
|
|
97
|
+
application/problem+json:
|
|
98
|
+
schema:
|
|
99
|
+
$ref: '#/components/schemas/ErrorResponse'
|
|
100
|
+
'401':
|
|
101
|
+
description: Unauthorized - invalid or missing authentication
|
|
102
|
+
content:
|
|
103
|
+
application/problem+json:
|
|
104
|
+
schema:
|
|
105
|
+
$ref: '#/components/schemas/ErrorResponse'
|
|
106
|
+
'403':
|
|
107
|
+
description: Forbidden - insufficient permissions
|
|
108
|
+
content:
|
|
109
|
+
application/problem+json:
|
|
110
|
+
schema:
|
|
111
|
+
$ref: '#/components/schemas/ErrorResponse'
|
|
112
|
+
'404':
|
|
113
|
+
description: Schema not found
|
|
114
|
+
content:
|
|
115
|
+
application/problem+json:
|
|
116
|
+
schema:
|
|
117
|
+
$ref: '#/components/schemas/ErrorResponse'
|
|
118
|
+
security:
|
|
119
|
+
- AmOAuth2:
|
|
120
|
+
- sfcc.scapi-schemas
|
|
121
|
+
components:
|
|
122
|
+
securitySchemes:
|
|
123
|
+
AmOAuth2:
|
|
124
|
+
type: oauth2
|
|
125
|
+
description: AccountManager OAuth 2.0 bearer token Authentication.
|
|
126
|
+
flows:
|
|
127
|
+
clientCredentials:
|
|
128
|
+
tokenUrl: https://account.demandware.com/dwsso/oauth2/access_token
|
|
129
|
+
scopes:
|
|
130
|
+
sfcc.scapi-schemas: SCAPI Schemas READONLY scope
|
|
131
|
+
authorizationCode:
|
|
132
|
+
authorizationUrl: https://account.demandware.com/dwsso/oauth2/authorize
|
|
133
|
+
tokenUrl: https://account.demandware.com/dwsso/oauth2/access_token
|
|
134
|
+
scopes:
|
|
135
|
+
sfcc.scapi-schemas: SCAPI Schemas READONLY scope
|
|
136
|
+
schemas:
|
|
137
|
+
OrganizationId:
|
|
138
|
+
description: An identifier for the organization the request is being made by
|
|
139
|
+
example: f_ecom_zzxy_prd
|
|
140
|
+
type: string
|
|
141
|
+
minLength: 1
|
|
142
|
+
maxLength: 32
|
|
143
|
+
SchemaStatus:
|
|
144
|
+
type: string
|
|
145
|
+
enum:
|
|
146
|
+
- current
|
|
147
|
+
- deprecated
|
|
148
|
+
example: current
|
|
149
|
+
Limit:
|
|
150
|
+
default: 10
|
|
151
|
+
minimum: 1
|
|
152
|
+
format: int32
|
|
153
|
+
description: Maximum records to retrieve per request, not to exceed the maximum defined. A limit must be at least 1 so at least one record is returned (if any match the criteria).
|
|
154
|
+
type: integer
|
|
155
|
+
example: 10
|
|
156
|
+
Total:
|
|
157
|
+
default: 0
|
|
158
|
+
minimum: 0
|
|
159
|
+
format: int32
|
|
160
|
+
description: The total number of hits that match the search's criteria. This can be greater than the number of results returned as search results are paginated.
|
|
161
|
+
type: integer
|
|
162
|
+
example: 10
|
|
163
|
+
ResultBase:
|
|
164
|
+
description: Schema defining generic list result. Each response schema of a resource requiring a list response should extend this schema.
|
|
165
|
+
type: object
|
|
166
|
+
required:
|
|
167
|
+
- limit
|
|
168
|
+
- total
|
|
169
|
+
properties:
|
|
170
|
+
limit:
|
|
171
|
+
maximum: 200
|
|
172
|
+
allOf:
|
|
173
|
+
- $ref: '#/components/schemas/Limit'
|
|
174
|
+
total:
|
|
175
|
+
$ref: '#/components/schemas/Total'
|
|
176
|
+
SchemaListFilter:
|
|
177
|
+
type: object
|
|
178
|
+
properties:
|
|
179
|
+
apiFamily:
|
|
180
|
+
type: string
|
|
181
|
+
example: shopper
|
|
182
|
+
apiName:
|
|
183
|
+
type: string
|
|
184
|
+
example: products
|
|
185
|
+
apiVersion:
|
|
186
|
+
type: string
|
|
187
|
+
example: v1
|
|
188
|
+
status:
|
|
189
|
+
$ref: '#/components/schemas/SchemaStatus'
|
|
190
|
+
SchemaListItem:
|
|
191
|
+
type: object
|
|
192
|
+
properties:
|
|
193
|
+
schemaVersion:
|
|
194
|
+
type: string
|
|
195
|
+
description: Semantic version of the schema (e.g., "1.0.0")
|
|
196
|
+
example: '1.0.0'
|
|
197
|
+
apiFamily:
|
|
198
|
+
type: string
|
|
199
|
+
description: The API family (e.g., shopper, admin)
|
|
200
|
+
example: shopper
|
|
201
|
+
apiName:
|
|
202
|
+
type: string
|
|
203
|
+
description: The API name (e.g., products, orders)
|
|
204
|
+
example: products
|
|
205
|
+
apiVersion:
|
|
206
|
+
type: string
|
|
207
|
+
description: The API version (e.g., v1)
|
|
208
|
+
example: v1
|
|
209
|
+
status:
|
|
210
|
+
$ref: '#/components/schemas/SchemaStatus'
|
|
211
|
+
link:
|
|
212
|
+
type: string
|
|
213
|
+
description: URL to the schema detail endpoint
|
|
214
|
+
example: /organizations/f_ecom_zzxy_prd/schemas/shopper/products/v1
|
|
215
|
+
SchemaListResult:
|
|
216
|
+
type: object
|
|
217
|
+
allOf:
|
|
218
|
+
- $ref: '#/components/schemas/ResultBase'
|
|
219
|
+
properties:
|
|
220
|
+
filter:
|
|
221
|
+
$ref: '#/components/schemas/SchemaListFilter'
|
|
222
|
+
data:
|
|
223
|
+
type: array
|
|
224
|
+
items:
|
|
225
|
+
$ref: '#/components/schemas/SchemaListItem'
|
|
226
|
+
OpenApiSchema:
|
|
227
|
+
type: object
|
|
228
|
+
description: An OpenAPI 3.0 schema specification
|
|
229
|
+
additionalProperties: true
|
|
230
|
+
properties:
|
|
231
|
+
openapi:
|
|
232
|
+
type: string
|
|
233
|
+
description: OpenAPI version
|
|
234
|
+
example: '3.0.3'
|
|
235
|
+
info:
|
|
236
|
+
type: object
|
|
237
|
+
additionalProperties: true
|
|
238
|
+
properties:
|
|
239
|
+
title:
|
|
240
|
+
type: string
|
|
241
|
+
version:
|
|
242
|
+
type: string
|
|
243
|
+
description:
|
|
244
|
+
type: string
|
|
245
|
+
paths:
|
|
246
|
+
type: object
|
|
247
|
+
additionalProperties: true
|
|
248
|
+
components:
|
|
249
|
+
type: object
|
|
250
|
+
additionalProperties: true
|
|
251
|
+
ErrorResponse:
|
|
252
|
+
type: object
|
|
253
|
+
additionalProperties: true
|
|
254
|
+
properties:
|
|
255
|
+
title:
|
|
256
|
+
description: A short, human-readable summary of the problem type.
|
|
257
|
+
type: string
|
|
258
|
+
maxLength: 256
|
|
259
|
+
example: Bad Request
|
|
260
|
+
type:
|
|
261
|
+
description: A URI reference that identifies the problem type.
|
|
262
|
+
type: string
|
|
263
|
+
maxLength: 2048
|
|
264
|
+
example: https://api.commercecloud.salesforce.com/documentation/error/v1/errors/bad-request
|
|
265
|
+
detail:
|
|
266
|
+
description: A human-readable explanation specific to this occurrence of the problem.
|
|
267
|
+
type: string
|
|
268
|
+
example: Invalid value for filter parameter.
|
|
269
|
+
instance:
|
|
270
|
+
description: A URI reference that identifies the specific occurrence of the problem.
|
|
271
|
+
type: string
|
|
272
|
+
maxLength: 2048
|
|
273
|
+
required:
|
|
274
|
+
- title
|
|
275
|
+
- type
|
|
276
|
+
- detail
|
|
277
|
+
parameters:
|
|
278
|
+
organizationId:
|
|
279
|
+
description: An identifier for the organization the request is being made by
|
|
280
|
+
name: organizationId
|
|
281
|
+
in: path
|
|
282
|
+
required: true
|
|
283
|
+
example: f_ecom_zzxy_prd
|
|
284
|
+
schema:
|
|
285
|
+
$ref: '#/components/schemas/OrganizationId'
|
|
286
|
+
apiFamily:
|
|
287
|
+
name: apiFamily
|
|
288
|
+
in: query
|
|
289
|
+
required: false
|
|
290
|
+
description: Filter by API family (e.g., shopper, admin)
|
|
291
|
+
schema:
|
|
292
|
+
type: string
|
|
293
|
+
apiName:
|
|
294
|
+
name: apiName
|
|
295
|
+
in: query
|
|
296
|
+
required: false
|
|
297
|
+
description: Filter by API name (e.g., products, orders)
|
|
298
|
+
schema:
|
|
299
|
+
type: string
|
|
300
|
+
apiVersion:
|
|
301
|
+
name: apiVersion
|
|
302
|
+
in: query
|
|
303
|
+
required: false
|
|
304
|
+
description: Filter by API version (e.g., v1)
|
|
305
|
+
schema:
|
|
306
|
+
type: string
|
|
307
|
+
status:
|
|
308
|
+
name: status
|
|
309
|
+
in: query
|
|
310
|
+
required: false
|
|
311
|
+
description: Filter by schema status
|
|
312
|
+
schema:
|
|
313
|
+
$ref: '#/components/schemas/SchemaStatus'
|
|
314
|
+
apiFamilyPath:
|
|
315
|
+
name: apiFamily
|
|
316
|
+
in: path
|
|
317
|
+
required: true
|
|
318
|
+
description: The API family (e.g., shopper, admin)
|
|
319
|
+
schema:
|
|
320
|
+
type: string
|
|
321
|
+
apiNamePath:
|
|
322
|
+
name: apiName
|
|
323
|
+
in: path
|
|
324
|
+
required: true
|
|
325
|
+
description: The API name (e.g., products, orders)
|
|
326
|
+
schema:
|
|
327
|
+
type: string
|
|
328
|
+
apiVersionPath:
|
|
329
|
+
name: apiVersion
|
|
330
|
+
in: path
|
|
331
|
+
required: true
|
|
332
|
+
description: The API version (e.g., v1)
|
|
333
|
+
schema:
|
|
334
|
+
type: string
|
|
335
|
+
expand:
|
|
336
|
+
name: expand
|
|
337
|
+
in: query
|
|
338
|
+
required: false
|
|
339
|
+
description: Comma-separated list of sections to expand (e.g., "custom_properties")
|
|
340
|
+
schema:
|
|
341
|
+
type: string
|