@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.
Files changed (34) hide show
  1. package/dist/cjs/clients/index.d.ts +3 -0
  2. package/dist/cjs/clients/index.js +2 -0
  3. package/dist/cjs/clients/index.js.map +1 -1
  4. package/dist/cjs/clients/middleware-registry.d.ts +1 -1
  5. package/dist/cjs/clients/scapi-schemas.d.ts +132 -0
  6. package/dist/cjs/clients/scapi-schemas.generated.d.ts +328 -0
  7. package/dist/cjs/clients/scapi-schemas.generated.js +6 -0
  8. package/dist/cjs/clients/scapi-schemas.generated.js.map +1 -0
  9. package/dist/cjs/clients/scapi-schemas.js +95 -0
  10. package/dist/cjs/clients/scapi-schemas.js.map +1 -0
  11. package/dist/cjs/operations/scapi-schemas/collapse.d.ts +150 -0
  12. package/dist/cjs/operations/scapi-schemas/collapse.js +180 -0
  13. package/dist/cjs/operations/scapi-schemas/collapse.js.map +1 -0
  14. package/dist/cjs/operations/scapi-schemas/index.d.ts +53 -0
  15. package/dist/cjs/operations/scapi-schemas/index.js +59 -0
  16. package/dist/cjs/operations/scapi-schemas/index.js.map +1 -0
  17. package/dist/esm/clients/index.d.ts +3 -0
  18. package/dist/esm/clients/index.js +2 -0
  19. package/dist/esm/clients/index.js.map +1 -1
  20. package/dist/esm/clients/middleware-registry.d.ts +1 -1
  21. package/dist/esm/clients/scapi-schemas.d.ts +132 -0
  22. package/dist/esm/clients/scapi-schemas.generated.d.ts +328 -0
  23. package/dist/esm/clients/scapi-schemas.generated.js +6 -0
  24. package/dist/esm/clients/scapi-schemas.generated.js.map +1 -0
  25. package/dist/esm/clients/scapi-schemas.js +95 -0
  26. package/dist/esm/clients/scapi-schemas.js.map +1 -0
  27. package/dist/esm/operations/scapi-schemas/collapse.d.ts +150 -0
  28. package/dist/esm/operations/scapi-schemas/collapse.js +180 -0
  29. package/dist/esm/operations/scapi-schemas/collapse.js.map +1 -0
  30. package/dist/esm/operations/scapi-schemas/index.d.ts +53 -0
  31. package/dist/esm/operations/scapi-schemas/index.js +59 -0
  32. package/dist/esm/operations/scapi-schemas/index.js.map +1 -0
  33. package/package.json +13 -2
  34. package/specs/scapi-schemas-v1.yaml +341 -0
@@ -0,0 +1,150 @@
1
+ /**
2
+ * OpenAPI schema collapsing utilities for agentic clients.
3
+ *
4
+ * These utilities implement a three-tier disclosure model for OpenAPI schemas:
5
+ * - **Collapsed** (default): Show structure only - paths as method names, schemas as keys
6
+ * - **Selective expansion**: Full details for specific items only
7
+ * - **Full expansion**: Complete schema without any collapsing
8
+ *
9
+ * This approach addresses context length concerns when working with large OpenAPI
10
+ * schemas in agentic/LLM contexts.
11
+ *
12
+ * @module operations/scapi-schemas/collapse
13
+ */
14
+ /**
15
+ * Options for collapsing an OpenAPI schema.
16
+ */
17
+ export interface SchemaCollapseOptions {
18
+ /**
19
+ * Paths to fully expand (e.g., ["/products", "/orders"]).
20
+ * When provided, only these paths will have full operation details.
21
+ * Other paths will show only their HTTP method names.
22
+ */
23
+ expandPaths?: string[];
24
+ /**
25
+ * Schema names to fully expand (e.g., ["Product", "Order"]).
26
+ * When provided, only these schemas will have full definitions.
27
+ * Other schemas will be shown as empty objects.
28
+ */
29
+ expandSchemas?: string[];
30
+ /**
31
+ * Example names to fully expand (e.g., ["ProductExample"]).
32
+ * When provided, only these examples will have full content.
33
+ * Other examples will be shown as empty objects.
34
+ */
35
+ expandExamples?: string[];
36
+ }
37
+ /**
38
+ * Represents an OpenAPI 3.x schema structure.
39
+ * This is a simplified type that captures the structure we need for collapsing.
40
+ */
41
+ export interface OpenApiSchemaInput {
42
+ openapi?: string;
43
+ info?: Record<string, unknown>;
44
+ servers?: unknown[];
45
+ paths?: Record<string, Record<string, unknown>>;
46
+ components?: {
47
+ schemas?: Record<string, unknown>;
48
+ examples?: Record<string, unknown>;
49
+ parameters?: Record<string, unknown>;
50
+ responses?: Record<string, unknown>;
51
+ requestBodies?: Record<string, unknown>;
52
+ headers?: Record<string, unknown>;
53
+ securitySchemes?: Record<string, unknown>;
54
+ links?: Record<string, unknown>;
55
+ callbacks?: Record<string, unknown>;
56
+ };
57
+ security?: unknown[];
58
+ tags?: unknown[];
59
+ externalDocs?: unknown;
60
+ [key: string]: unknown;
61
+ }
62
+ /**
63
+ * Represents a collapsed path entry.
64
+ * When collapsed, a path only shows the HTTP methods it supports.
65
+ */
66
+ export type CollapsedPath = string[] | Record<string, unknown>;
67
+ /**
68
+ * The output schema structure after collapsing.
69
+ */
70
+ export interface CollapsedOpenApiSchema {
71
+ openapi?: string;
72
+ info?: Record<string, unknown>;
73
+ servers?: unknown[];
74
+ paths?: Record<string, CollapsedPath>;
75
+ components?: {
76
+ schemas?: Record<string, unknown>;
77
+ examples?: Record<string, unknown>;
78
+ parameters?: Record<string, unknown>;
79
+ responses?: Record<string, unknown>;
80
+ requestBodies?: Record<string, unknown>;
81
+ headers?: Record<string, unknown>;
82
+ securitySchemes?: Record<string, unknown>;
83
+ links?: Record<string, unknown>;
84
+ callbacks?: Record<string, unknown>;
85
+ };
86
+ security?: unknown[];
87
+ tags?: unknown[];
88
+ externalDocs?: unknown;
89
+ [key: string]: unknown;
90
+ }
91
+ /**
92
+ * Collapses an OpenAPI schema for context-efficient representation.
93
+ *
94
+ * This function implements a three-tier disclosure model:
95
+ *
96
+ * 1. **No options provided (default):**
97
+ * - Paths: `{"/products": ["get", "post"]}` (method names only)
98
+ * - Schemas: `{"Product": {}}` (keys only)
99
+ * - Examples: `{"ProductExample": {}}` (keys only)
100
+ *
101
+ * 2. **Selective expansion:**
102
+ * - Only specified paths/schemas/examples are fully expanded
103
+ * - Everything else remains collapsed
104
+ *
105
+ * Non-collapsible sections (info, servers, security, tags, etc.) are preserved as-is.
106
+ *
107
+ * @param schema - The OpenAPI schema to collapse
108
+ * @param options - Options controlling what to expand
109
+ * @returns The collapsed schema
110
+ *
111
+ * @example
112
+ * // Collapse everything (default behavior)
113
+ * const collapsed = collapseOpenApiSchema(fullSchema);
114
+ *
115
+ * @example
116
+ * // Expand only /products path and Product schema
117
+ * const collapsed = collapseOpenApiSchema(fullSchema, {
118
+ * expandPaths: ['/products'],
119
+ * expandSchemas: ['Product']
120
+ * });
121
+ */
122
+ export declare function collapseOpenApiSchema(schema: OpenApiSchemaInput, options?: SchemaCollapseOptions): CollapsedOpenApiSchema;
123
+ /**
124
+ * Checks if a schema has been collapsed (i.e., is in outline form).
125
+ *
126
+ * @param schema - The schema to check
127
+ * @returns true if paths are collapsed (arrays) or schemas are empty objects
128
+ */
129
+ export declare function isCollapsedSchema(schema: CollapsedOpenApiSchema): boolean;
130
+ /**
131
+ * Gets the list of available path keys from a schema.
132
+ *
133
+ * @param schema - The OpenAPI schema
134
+ * @returns Array of path keys (e.g., ["/products", "/orders"])
135
+ */
136
+ export declare function getPathKeys(schema: OpenApiSchemaInput | CollapsedOpenApiSchema): string[];
137
+ /**
138
+ * Gets the list of available schema names from a schema.
139
+ *
140
+ * @param schema - The OpenAPI schema
141
+ * @returns Array of schema names (e.g., ["Product", "Order"])
142
+ */
143
+ export declare function getSchemaNames(schema: OpenApiSchemaInput | CollapsedOpenApiSchema): string[];
144
+ /**
145
+ * Gets the list of available example names from a schema.
146
+ *
147
+ * @param schema - The OpenAPI schema
148
+ * @returns Array of example names
149
+ */
150
+ export declare function getExampleNames(schema: OpenApiSchemaInput | CollapsedOpenApiSchema): string[];
@@ -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
+ {"version":3,"file":"collapse.js","sourceRoot":"","sources":["../../../../src/operations/scapi-schemas/collapse.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmGH,oDAAoD;AACpD,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAU,CAAC;AAEpG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAA0B,EAC1B,UAAiC,EAAE;IAEnC,MAAM,EAAC,WAAW,GAAG,EAAE,EAAE,aAAa,GAAG,EAAE,EAAE,cAAc,GAAG,EAAE,EAAC,GAAG,OAAO,CAAC;IAE5E,4BAA4B;IAC5B,MAAM,MAAM,GAA2B,EAAC,GAAG,MAAM,EAAC,CAA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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"}
@@ -11,6 +11,7 @@
11
11
  * - {@link SlasClient} - SLAS Admin API for managing tenants and clients
12
12
  * - {@link OdsClient} - On-Demand Sandbox API for managing developer sandboxes
13
13
  * - {@link CustomApisClient} - Custom APIs DX API for retrieving endpoint status
14
+ * - {@link ScapiSchemasClient} - SCAPI Schemas API for discovering and retrieving OpenAPI schemas
14
15
  *
15
16
  * ## Usage
16
17
  *
@@ -125,3 +126,5 @@ export { createMrtClient, DEFAULT_MRT_ORIGIN } from './mrt.js';
125
126
  export type { MrtClient, MrtClientConfig, MrtError, MrtResponse, BuildPushResponse, paths as MrtPaths, components as MrtComponents, } from './mrt.js';
126
127
  export { createCustomApisClient, toOrganizationId, toTenantId, buildTenantScope, ORGANIZATION_ID_PREFIX, SCAPI_TENANT_SCOPE_PREFIX, CUSTOM_APIS_DEFAULT_SCOPES, } from './custom-apis.js';
127
128
  export type { CustomApisClient, CustomApisClientConfig, CustomApisError, CustomApisResponse, paths as CustomApisPaths, components as CustomApisComponents, } from './custom-apis.js';
129
+ export { createScapiSchemasClient, SCAPI_SCHEMAS_DEFAULT_SCOPES } from './scapi-schemas.js';
130
+ export type { ScapiSchemasClient, ScapiSchemasClientConfig, ScapiSchemasError, ScapiSchemasResponse, SchemaListItem, SchemaListResult, OpenApiSchema, paths as ScapiSchemasPaths, components as ScapiSchemasComponents, } from './scapi-schemas.js';
@@ -16,6 +16,7 @@
16
16
  * - {@link SlasClient} - SLAS Admin API for managing tenants and clients
17
17
  * - {@link OdsClient} - On-Demand Sandbox API for managing developer sandboxes
18
18
  * - {@link CustomApisClient} - Custom APIs DX API for retrieving endpoint status
19
+ * - {@link ScapiSchemasClient} - SCAPI Schemas API for discovering and retrieving OpenAPI schemas
19
20
  *
20
21
  * ## Usage
21
22
  *
@@ -122,4 +123,5 @@ export { createSlasClient } from './slas-admin.js';
122
123
  export { createOdsClient } from './ods.js';
123
124
  export { createMrtClient, DEFAULT_MRT_ORIGIN } from './mrt.js';
124
125
  export { createCustomApisClient, toOrganizationId, toTenantId, buildTenantScope, ORGANIZATION_ID_PREFIX, SCAPI_TENANT_SCOPE_PREFIX, CUSTOM_APIS_DEFAULT_SCOPES, } from './custom-apis.js';
126
+ export { createScapiSchemasClient, SCAPI_SCHEMAS_DEFAULT_SCOPES } from './scapi-schemas.js';
125
127
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/clients/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8GG;AACH,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAC,oBAAoB,EAAE,uBAAuB,EAAE,2BAA2B,EAAC,MAAM,iBAAiB,CAAC;AAG3G,OAAO,EAAC,kBAAkB,EAAE,wBAAwB,EAAC,MAAM,0BAA0B,CAAC;AAGtF,OAAO,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAU7C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAUjD,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAC;AAUzC,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAC,MAAM,UAAU,CAAC;AAW7D,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/clients/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAC,oBAAoB,EAAE,uBAAuB,EAAE,2BAA2B,EAAC,MAAM,iBAAiB,CAAC;AAG3G,OAAO,EAAC,kBAAkB,EAAE,wBAAwB,EAAC,MAAM,0BAA0B,CAAC;AAGtF,OAAO,EAAC,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAU7C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAUjD,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAC;AAUzC,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAC,MAAM,UAAU,CAAC;AAW7D,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAU1B,OAAO,EAAC,wBAAwB,EAAE,4BAA4B,EAAC,MAAM,oBAAoB,CAAC"}
@@ -38,7 +38,7 @@ import type { Middleware } from 'openapi-fetch';
38
38
  /**
39
39
  * Types of HTTP clients that can receive middleware.
40
40
  */
41
- export type HttpClientType = 'ocapi' | 'slas' | 'ods' | 'mrt' | 'custom-apis' | 'webdav';
41
+ export type HttpClientType = 'ocapi' | 'slas' | 'ods' | 'mrt' | 'custom-apis' | 'scapi-schemas' | 'webdav';
42
42
  /**
43
43
  * Middleware interface compatible with openapi-fetch.
44
44
  *
@@ -0,0 +1,132 @@
1
+ /**
2
+ * SCAPI Schemas API client for B2C Commerce.
3
+ *
4
+ * Provides a fully typed client for SCAPI Schemas API operations using
5
+ * openapi-fetch with OAuth authentication middleware. Used for discovering
6
+ * and retrieving OpenAPI schema specifications for SCAPI APIs.
7
+ *
8
+ * @module clients/scapi-schemas
9
+ */
10
+ import { type Client } from 'openapi-fetch';
11
+ import type { AuthStrategy } from '../auth/types.js';
12
+ import type { paths, components } from './scapi-schemas.generated.js';
13
+ import { type MiddlewareRegistry } from './middleware-registry.js';
14
+ import { toOrganizationId, toTenantId, buildTenantScope } from './custom-apis.js';
15
+ /**
16
+ * Re-export generated types for external use.
17
+ */
18
+ export type { paths, components };
19
+ /**
20
+ * Re-export organization/tenant utilities for convenience.
21
+ */
22
+ export { toOrganizationId, toTenantId, buildTenantScope };
23
+ /**
24
+ * The typed SCAPI Schemas client - this is the openapi-fetch Client with full type safety.
25
+ *
26
+ * @see {@link createScapiSchemasClient} for instantiation
27
+ */
28
+ export type ScapiSchemasClient = Client<paths>;
29
+ /**
30
+ * Helper type to extract response data from an operation.
31
+ */
32
+ export type ScapiSchemasResponse<T> = T extends {
33
+ content: {
34
+ 'application/json': infer R;
35
+ };
36
+ } ? R : never;
37
+ /**
38
+ * Standard SCAPI Schemas error response structure.
39
+ */
40
+ export type ScapiSchemasError = components['schemas']['ErrorResponse'];
41
+ /**
42
+ * Schema list item from the list endpoint.
43
+ */
44
+ export type SchemaListItem = components['schemas']['SchemaListItem'];
45
+ /**
46
+ * Schema list result from the list endpoint.
47
+ */
48
+ export type SchemaListResult = components['schemas']['SchemaListResult'];
49
+ /**
50
+ * OpenAPI schema structure returned by the get endpoint.
51
+ */
52
+ export type OpenApiSchema = components['schemas']['OpenApiSchema'];
53
+ /** Default OAuth scopes required for SCAPI Schemas (read-only) */
54
+ export declare const SCAPI_SCHEMAS_DEFAULT_SCOPES: string[];
55
+ /**
56
+ * Configuration for creating a SCAPI Schemas client.
57
+ */
58
+ export interface ScapiSchemasClientConfig {
59
+ /**
60
+ * The short code for the SCAPI instance.
61
+ * This is typically a 4-8 character alphanumeric code.
62
+ * @example "kv7kzm78"
63
+ */
64
+ shortCode: string;
65
+ /**
66
+ * The tenant ID (with or without f_ecom_ prefix).
67
+ * Used to build the organizationId path parameter and tenant-specific OAuth scope.
68
+ * @example "zzxy_prd" or "f_ecom_zzxy_prd"
69
+ */
70
+ tenantId: string;
71
+ /**
72
+ * Optional scope override. If not provided, defaults to domain scope
73
+ * (sfcc.scapi-schemas) plus tenant-specific scope (SALESFORCE_COMMERCE_API:{tenant}).
74
+ */
75
+ scopes?: string[];
76
+ /**
77
+ * Middleware registry to use for this client.
78
+ * If not specified, uses the global middleware registry.
79
+ */
80
+ middlewareRegistry?: MiddlewareRegistry;
81
+ }
82
+ /**
83
+ * Creates a typed SCAPI Schemas API client.
84
+ *
85
+ * Returns the openapi-fetch client directly, with authentication
86
+ * handled via middleware. This gives full access to all openapi-fetch
87
+ * features with type-safe paths, parameters, and responses.
88
+ *
89
+ * The client automatically handles OAuth scope requirements:
90
+ * - Domain scope: `sfcc.scapi-schemas` (or custom via config.scopes)
91
+ * - Tenant scope: `SALESFORCE_COMMERCE_API:{tenantId}`
92
+ *
93
+ * @param config - SCAPI Schemas client configuration including shortCode and tenantId
94
+ * @param auth - Authentication strategy (typically OAuth)
95
+ * @returns Typed openapi-fetch client
96
+ *
97
+ * @example
98
+ * // Create SCAPI Schemas client - scopes are handled automatically
99
+ * const oauthStrategy = new OAuthStrategy({
100
+ * clientId: 'your-client-id',
101
+ * clientSecret: 'your-client-secret',
102
+ * });
103
+ *
104
+ * const client = createScapiSchemasClient(
105
+ * { shortCode: 'kv7kzm78', tenantId: 'zzxy_prd' },
106
+ * oauthStrategy
107
+ * );
108
+ *
109
+ * // List available SCAPI schemas
110
+ * const { data, error } = await client.GET('/organizations/{organizationId}/schemas', {
111
+ * params: {
112
+ * path: { organizationId: toOrganizationId('zzxy_prd') }
113
+ * }
114
+ * });
115
+ *
116
+ * // Get a specific schema
117
+ * const { data: schema } = await client.GET(
118
+ * '/organizations/{organizationId}/schemas/{apiFamily}/{apiName}/{apiVersion}',
119
+ * {
120
+ * params: {
121
+ * path: {
122
+ * organizationId: toOrganizationId('zzxy_prd'),
123
+ * apiFamily: 'shopper',
124
+ * apiName: 'products',
125
+ * apiVersion: 'v1'
126
+ * },
127
+ * query: { expand: 'custom_properties' }
128
+ * }
129
+ * }
130
+ * );
131
+ */
132
+ export declare function createScapiSchemasClient(config: ScapiSchemasClientConfig, auth: AuthStrategy): ScapiSchemasClient;