@adobe/aio-commerce-lib-auth 0.2.0 → 0.3.1

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.
@@ -1,88 +1,227 @@
1
- import { ErrorType, Result } from "@adobe/aio-commerce-lib-core/result";
2
- import { ValidationErrorType } from "@adobe/aio-commerce-lib-core/validation";
3
- import * as valibot25 from "valibot";
4
- import { InferInput, InferIssue, InferOutput } from "valibot";
5
- import * as url5 from "url";
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2025 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import * as valibot21 from "valibot";
16
+ import { InferOutput } from "valibot";
6
17
 
7
18
  //#region source/lib/ims-auth/schema.d.ts
19
+ /** The environments accepted by the IMS auth service. */
8
20
  declare const IMS_AUTH_ENV: {
9
21
  readonly PROD: "prod";
10
22
  readonly STAGE: "stage";
11
23
  };
12
- declare const ImsAuthEnvSchema: valibot25.EnumSchema<{
24
+ /** Validation schema for IMS auth environment values. */
25
+ declare const ImsAuthEnvSchema: valibot21.EnumSchema<{
13
26
  readonly PROD: "prod";
14
27
  readonly STAGE: "stage";
15
28
  }, undefined>;
16
- declare const ImsAuthParamsSchema: valibot25.ObjectSchema<{
17
- readonly AIO_COMMERCE_IMS_CLIENT_ID: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
18
- readonly AIO_COMMERCE_IMS_CLIENT_SECRETS: valibot25.SchemaWithPipe<readonly [valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>, valibot25.ParseJsonAction<string, undefined, undefined>]>, valibot25.ArraySchema<valibot25.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>;
19
- readonly AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
20
- readonly AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
21
- readonly AIO_COMMERCE_IMS_IMS_ORG_ID: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
22
- readonly AIO_COMMERCE_IMS_ENV: valibot25.SchemaWithPipe<readonly [valibot25.OptionalSchema<valibot25.EnumSchema<{
29
+ /** Defines the schema to validate the necessary parameters for the IMS auth service. */
30
+ declare const ImsAuthParamsSchema: valibot21.ObjectSchema<{
31
+ readonly clientId: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
32
+ readonly clientSecrets: valibot21.SchemaWithPipe<readonly [valibot21.SchemaWithPipe<readonly [valibot21.ArraySchema<valibot21.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot21.MinLengthAction<string[], 1, "Expected at least one client secret for IMS auth">]>;
33
+ readonly technicalAccountId: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
34
+ readonly technicalAccountEmail: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<"Expected a string value for the IMS auth parameter technicalAccountEmail">, valibot21.EmailAction<string, "Expected a valid email format for technicalAccountEmail">]>;
35
+ readonly imsOrgId: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
36
+ readonly environment: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.EnumSchema<{
23
37
  readonly PROD: "prod";
24
38
  readonly STAGE: "stage";
25
39
  }, undefined>, "prod">]>;
26
- readonly AIO_COMMERCE_IMS_CTX: valibot25.SchemaWithPipe<readonly [valibot25.OptionalSchema<valibot25.StringSchema<undefined>, "aio-commerce-sdk-creds">]>;
27
- readonly AIO_COMMERCE_IMS_SCOPES: valibot25.SchemaWithPipe<readonly [valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>, valibot25.ParseJsonAction<string, undefined, undefined>]>, valibot25.ArraySchema<valibot25.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>;
40
+ readonly context: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.StringSchema<undefined>, "aio-commerce-sdk-creds">]>;
41
+ readonly scopes: valibot21.SchemaWithPipe<readonly [valibot21.SchemaWithPipe<readonly [valibot21.ArraySchema<valibot21.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot21.MinLengthAction<string[], 1, "Expected at least one scope for IMS auth">]>;
28
42
  }, undefined>;
43
+ /** Defines the parameters for the IMS auth service. */
29
44
  type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
45
+ /** Defines the environments accepted by the IMS auth service. */
30
46
  type ImsAuthEnv = InferOutput<typeof ImsAuthEnvSchema>;
31
47
  //#endregion
32
48
  //#region source/lib/ims-auth/provider.d.ts
33
- type ImsAccessToken = string;
49
+ /** Defines the header keys used for IMS authentication. */
34
50
  type ImsAuthHeader = "Authorization" | "x-api-key";
51
+ /** Defines the headers required for IMS authentication. */
35
52
  type ImsAuthHeaders = Record<ImsAuthHeader, string>;
36
- type ImsAuthValidationError = ValidationErrorType<"ImsAuthValidationError", InferIssue<typeof ImsAuthParamsSchema>[]>;
37
- type ImsAuthError<TError = unknown> = ErrorType<"ImsAuthError", {
38
- message: string;
39
- error: TError;
40
- }>;
41
- interface ImsAuthConfig {
42
- clientId: string;
43
- clientSecrets: string[];
44
- technicalAccountId: string;
45
- technicalAccountEmail: string;
46
- imsOrgId: string;
47
- scopes: string[];
48
- environment: ImsAuthEnv;
49
- context: string;
50
- }
53
+ /** Defines an authentication provider for Adobe IMS. */
51
54
  interface ImsAuthProvider {
52
- getAccessToken: () => Promise<Result<ImsAccessToken, ImsAuthError>>;
53
- getHeaders: () => Promise<Result<ImsAuthHeaders, ImsAuthError>>;
55
+ getAccessToken: () => Promise<string>;
56
+ getHeaders: () => Promise<ImsAuthHeaders>;
54
57
  }
55
- declare function getImsAuthProvider(config: ImsAuthConfig): ImsAuthProvider;
56
- declare function tryGetImsAuthProvider(params: InferInput<typeof ImsAuthParamsSchema>): Result<ImsAuthProvider, ImsAuthValidationError>;
58
+ /**
59
+ * Asserts the provided configuration for an {@link ImsAuthProvider}.
60
+ * @param config The configuration to validate.
61
+ * @throws {CommerceSdkValidationError} If the configuration is invalid.
62
+ * @example
63
+ * ```typescript
64
+ * const config = {
65
+ * clientId: "your-client-id",
66
+ * clientSecrets: ["your-client-secret"],
67
+ * technicalAccountId: "your-technical-account-id",
68
+ * technicalAccountEmail: "your-account@example.com",
69
+ * imsOrgId: "your-ims-org-id@AdobeOrg",
70
+ * scopes: ["AdobeID", "openid"],
71
+ * environment: "prod", // or "stage"
72
+ * context: "my-app-context"
73
+ * };
74
+ *
75
+ * // This will validate the config and throw if invalid
76
+ * assertImsAuthParams(config);
77
+ *```
78
+ * @example
79
+ * ```typescript
80
+ * // Example of a failing assert:
81
+ * try {
82
+ * assertImsAuthParams({
83
+ * clientId: "valid-client-id",
84
+ * // Missing required fields like clientSecrets, technicalAccountId, etc.
85
+ * });
86
+ * } catch (error) {
87
+ * console.error(error.message); // "Invalid ImsAuthProvider configuration"
88
+ * console.error(error.issues); // Array of validation issues
89
+ * }
90
+ * ```
91
+ */
92
+ declare function assertImsAuthParams(config: Record<PropertyKey, unknown>): asserts config is ImsAuthParams;
93
+ /**
94
+ * Creates an {@link ImsAuthProvider} based on the provided configuration.
95
+ * @param authParams An {@link ImsAuthParams} parameter that contains the configuration for the {@link ImsAuthProvider}.
96
+ * @returns An {@link ImsAuthProvider} instance that can be used to get access token and auth headers.
97
+ * @example
98
+ * ```typescript
99
+ * const config = {
100
+ * clientId: "your-client-id",
101
+ * clientSecrets: ["your-client-secret"],
102
+ * technicalAccountId: "your-technical-account-id",
103
+ * technicalAccountEmail: "your-account@example.com",
104
+ * imsOrgId: "your-ims-org-id@AdobeOrg",
105
+ * scopes: ["AdobeID", "openid"],
106
+ * environment: "prod",
107
+ * context: "my-app-context"
108
+ * };
109
+ *
110
+ * const authProvider = getImsAuthProvider(config);
111
+ *
112
+ * // Get access token
113
+ * const token = await authProvider.getAccessToken();
114
+ * console.log(token); // "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..."
115
+ *
116
+ * // Get headers for API requests
117
+ * const headers = await authProvider.getHeaders();
118
+ * console.log(headers);
119
+ * // {
120
+ * // Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
121
+ * // "x-api-key": "your-client-id"
122
+ * // }
123
+ *
124
+ * // Use headers in API calls
125
+ * const response = await fetch('https://api.adobe.io/some-endpoint', {
126
+ * headers: await authProvider.getHeaders()
127
+ * });
128
+ * ```
129
+ */
130
+ declare function getImsAuthProvider(authParams: ImsAuthParams): {
131
+ getAccessToken: () => Promise<string>;
132
+ getHeaders: () => Promise<{
133
+ Authorization: string;
134
+ "x-api-key": string;
135
+ }>;
136
+ };
57
137
  //#endregion
58
138
  //#region source/lib/integration-auth/schema.d.ts
59
- declare const HttpMethodSchema: valibot25.PicklistSchema<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"], undefined>;
60
- type HttpMethodInput = InferInput<typeof HttpMethodSchema>;
61
- declare const UrlSchema: valibot25.SchemaWithPipe<readonly [valibot25.UnionSchema<[valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<"Expected a string for the Adobe Commerce endpoint">, valibot25.NonEmptyAction<string, "Expected a non-empty string for the Adobe Commerce endpoint">, valibot25.UrlAction<string, "Expected a valid url for the Adobe Commerce endpoint">]>, valibot25.InstanceSchema<typeof url5.URL, undefined>], undefined>, valibot25.TransformAction<string | url5.URL, string>]>;
62
- type AdobeCommerceUri = InferInput<typeof UrlSchema>;
63
- declare const IntegrationAuthParamsSchema: valibot25.NonOptionalSchema<valibot25.ObjectSchema<{
64
- readonly AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
65
- readonly AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
66
- readonly AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
67
- readonly AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET: valibot25.SchemaWithPipe<readonly [valibot25.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot25.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
139
+ /**
140
+ * The HTTP methods supported by Commerce.
141
+ * This is used to determine which headers to include in the signing of the authorization header.
142
+ */
143
+ type HttpMethodInput = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
144
+ /** Validation schema that accepts either a URL string or URL instance and normalizes to string. */
145
+
146
+ /**
147
+ * The schema for the Commerce Integration parameters.
148
+ * This is used to validate the parameters passed to the Commerce Integration provider.
149
+ */
150
+ declare const IntegrationAuthParamsSchema: valibot21.NonOptionalSchema<valibot21.ObjectSchema<{
151
+ readonly consumerKey: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
152
+ readonly consumerSecret: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
153
+ readonly accessToken: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
154
+ readonly accessTokenSecret: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
68
155
  }, undefined>, undefined>;
69
- type IntegrationAuthParams = InferInput<typeof IntegrationAuthParamsSchema>;
156
+ /** Defines the parameters required for Commerce Integration authentication. */
157
+ type IntegrationAuthParams = InferOutput<typeof IntegrationAuthParamsSchema>;
70
158
  //#endregion
71
159
  //#region source/lib/integration-auth/provider.d.ts
160
+ /** Defines the header key used for Commerce Integration authentication. */
72
161
  type IntegrationAuthHeader = "Authorization";
162
+ /** Defines the headers required for Commerce Integration authentication. */
73
163
  type IntegrationAuthHeaders = Record<IntegrationAuthHeader, string>;
74
- interface IntegrationConfig {
75
- consumerKey: string;
76
- consumerSecret: string;
77
- accessToken: string;
78
- accessTokenSecret: string;
79
- }
80
- type ValidationIssues = InferIssue<typeof IntegrationAuthParamsSchema>[] | InferIssue<typeof UrlSchema>[];
81
- type IntegrationAuthError = ValidationErrorType<"IntegrationAuthValidationError", ValidationIssues>;
164
+ /** Represents a URL for Adobe Commerce endpoints, accepting either string or URL object. */
165
+ type AdobeCommerceUrl = string | URL;
166
+ /** Defines an authentication provider for Adobe Commerce integrations. */
82
167
  interface IntegrationAuthProvider {
83
- getHeaders: (method: HttpMethodInput, url: AdobeCommerceUri) => Result<IntegrationAuthHeaders, IntegrationAuthError>;
168
+ getHeaders: (method: HttpMethodInput, url: AdobeCommerceUrl) => IntegrationAuthHeaders;
84
169
  }
85
- declare function getIntegrationAuthProvider(config: IntegrationConfig): IntegrationAuthProvider;
86
- declare function tryGetIntegrationAuthProvider(params: IntegrationAuthParams): Result<IntegrationAuthProvider, IntegrationAuthError>;
170
+ /**
171
+ * Asserts the provided configuration for an Adobe Commerce {@link IntegrationAuthProvider}.
172
+ * @param config The configuration to validate.
173
+ * @throws {CommerceSdkValidationError} If the configuration is invalid.
174
+ * @example
175
+ * ```typescript
176
+ * const config = {
177
+ * consumerKey: "your-consumer-key",
178
+ * consumerSecret: "your-consumer-secret",
179
+ * accessToken: "your-access-token",
180
+ * accessTokenSecret: "your-access-token-secret"
181
+ * };
182
+ *
183
+ * // This will validate the config and throw if invalid
184
+ * assertIntegrationAuthParams(config);
185
+ * ```
186
+ * @example
187
+ * ```typescript
188
+ * // Example of a failing assert:
189
+ * try {
190
+ * assertIntegrationAuthParams({
191
+ * consumerKey: "valid-consumer-key",
192
+ * // Missing required fields like consumerSecret, accessToken, accessTokenSecret
193
+ * });
194
+ * } catch (error) {
195
+ * console.error(error.message); // "Invalid IntegrationAuthProvider configuration"
196
+ * console.error(error.issues); // Array of validation issues
197
+ * }
198
+ * ```
199
+ */
200
+ declare function assertIntegrationAuthParams(config: Record<PropertyKey, unknown>): asserts config is IntegrationAuthParams;
201
+ /**
202
+ * Creates an {@link IntegrationAuthProvider} based on the provided configuration.
203
+ * @param authParams The configuration for the integration.
204
+ * @returns An {@link IntegrationAuthProvider} instance that can be used to get auth headers.
205
+ * @example
206
+ * ```typescript
207
+ * const config = {
208
+ * consumerKey: "your-consumer-key",
209
+ * consumerSecret: "your-consumer-secret",
210
+ * accessToken: "your-access-token",
211
+ * accessTokenSecret: "your-access-token-secret"
212
+ * };
213
+ *
214
+ * const authProvider = getIntegrationAuthProvider(config);
215
+ *
216
+ * // Get OAuth headers for a REST API call
217
+ * const headers = authProvider.getHeaders("GET", "https://your-store.com/rest/V1/products");
218
+ * console.log(headers); // { Authorization: "OAuth oauth_consumer_key=..., oauth_signature=..." }
219
+ *
220
+ * // Can also be used with URL objects
221
+ * const url = new URL("https://your-store.com/rest/V1/customers");
222
+ * const postHeaders = authProvider.getHeaders("POST", url);
223
+ * ```
224
+ */
225
+ declare function getIntegrationAuthProvider(authParams: IntegrationAuthParams): IntegrationAuthProvider;
87
226
  //#endregion
88
- export { IMS_AUTH_ENV, ImsAuthConfig, ImsAuthEnv, ImsAuthError, ImsAuthParams, ImsAuthProvider, IntegrationAuthError, IntegrationAuthParams, IntegrationAuthProvider, IntegrationConfig, getImsAuthProvider, getIntegrationAuthProvider, tryGetImsAuthProvider, tryGetIntegrationAuthProvider };
227
+ export { IMS_AUTH_ENV, type ImsAuthEnv, type ImsAuthParams, type ImsAuthProvider, type IntegrationAuthParams, type IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
@@ -1,88 +1,227 @@
1
- import { ErrorType, Result } from "@adobe/aio-commerce-lib-core/result";
2
- import * as valibot0 from "valibot";
3
- import { InferInput, InferIssue, InferOutput } from "valibot";
4
- import { ValidationErrorType } from "@adobe/aio-commerce-lib-core/validation";
5
- import * as url39 from "url";
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2025 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import * as valibot21 from "valibot";
16
+ import { InferOutput } from "valibot";
6
17
 
7
18
  //#region source/lib/ims-auth/schema.d.ts
19
+ /** The environments accepted by the IMS auth service. */
8
20
  declare const IMS_AUTH_ENV: {
9
21
  readonly PROD: "prod";
10
22
  readonly STAGE: "stage";
11
23
  };
12
- declare const ImsAuthEnvSchema: valibot0.EnumSchema<{
24
+ /** Validation schema for IMS auth environment values. */
25
+ declare const ImsAuthEnvSchema: valibot21.EnumSchema<{
13
26
  readonly PROD: "prod";
14
27
  readonly STAGE: "stage";
15
28
  }, undefined>;
16
- declare const ImsAuthParamsSchema: valibot0.ObjectSchema<{
17
- readonly AIO_COMMERCE_IMS_CLIENT_ID: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
18
- readonly AIO_COMMERCE_IMS_CLIENT_SECRETS: valibot0.SchemaWithPipe<readonly [valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>, valibot0.ParseJsonAction<string, undefined, undefined>]>, valibot0.ArraySchema<valibot0.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>;
19
- readonly AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
20
- readonly AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
21
- readonly AIO_COMMERCE_IMS_IMS_ORG_ID: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
22
- readonly AIO_COMMERCE_IMS_ENV: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.EnumSchema<{
29
+ /** Defines the schema to validate the necessary parameters for the IMS auth service. */
30
+ declare const ImsAuthParamsSchema: valibot21.ObjectSchema<{
31
+ readonly clientId: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
32
+ readonly clientSecrets: valibot21.SchemaWithPipe<readonly [valibot21.SchemaWithPipe<readonly [valibot21.ArraySchema<valibot21.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot21.MinLengthAction<string[], 1, "Expected at least one client secret for IMS auth">]>;
33
+ readonly technicalAccountId: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
34
+ readonly technicalAccountEmail: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<"Expected a string value for the IMS auth parameter technicalAccountEmail">, valibot21.EmailAction<string, "Expected a valid email format for technicalAccountEmail">]>;
35
+ readonly imsOrgId: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
36
+ readonly environment: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.EnumSchema<{
23
37
  readonly PROD: "prod";
24
38
  readonly STAGE: "stage";
25
39
  }, undefined>, "prod">]>;
26
- readonly AIO_COMMERCE_IMS_CTX: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.StringSchema<undefined>, "aio-commerce-sdk-creds">]>;
27
- readonly AIO_COMMERCE_IMS_SCOPES: valibot0.SchemaWithPipe<readonly [valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>, valibot0.ParseJsonAction<string, undefined, undefined>]>, valibot0.ArraySchema<valibot0.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>;
40
+ readonly context: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.StringSchema<undefined>, "aio-commerce-sdk-creds">]>;
41
+ readonly scopes: valibot21.SchemaWithPipe<readonly [valibot21.SchemaWithPipe<readonly [valibot21.ArraySchema<valibot21.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot21.MinLengthAction<string[], 1, "Expected at least one scope for IMS auth">]>;
28
42
  }, undefined>;
43
+ /** Defines the parameters for the IMS auth service. */
29
44
  type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
45
+ /** Defines the environments accepted by the IMS auth service. */
30
46
  type ImsAuthEnv = InferOutput<typeof ImsAuthEnvSchema>;
31
47
  //#endregion
32
48
  //#region source/lib/ims-auth/provider.d.ts
33
- type ImsAccessToken = string;
49
+ /** Defines the header keys used for IMS authentication. */
34
50
  type ImsAuthHeader = "Authorization" | "x-api-key";
51
+ /** Defines the headers required for IMS authentication. */
35
52
  type ImsAuthHeaders = Record<ImsAuthHeader, string>;
36
- type ImsAuthValidationError = ValidationErrorType<"ImsAuthValidationError", InferIssue<typeof ImsAuthParamsSchema>[]>;
37
- type ImsAuthError<TError = unknown> = ErrorType<"ImsAuthError", {
38
- message: string;
39
- error: TError;
40
- }>;
41
- interface ImsAuthConfig {
42
- clientId: string;
43
- clientSecrets: string[];
44
- technicalAccountId: string;
45
- technicalAccountEmail: string;
46
- imsOrgId: string;
47
- scopes: string[];
48
- environment: ImsAuthEnv;
49
- context: string;
50
- }
53
+ /** Defines an authentication provider for Adobe IMS. */
51
54
  interface ImsAuthProvider {
52
- getAccessToken: () => Promise<Result<ImsAccessToken, ImsAuthError>>;
53
- getHeaders: () => Promise<Result<ImsAuthHeaders, ImsAuthError>>;
55
+ getAccessToken: () => Promise<string>;
56
+ getHeaders: () => Promise<ImsAuthHeaders>;
54
57
  }
55
- declare function getImsAuthProvider(config: ImsAuthConfig): ImsAuthProvider;
56
- declare function tryGetImsAuthProvider(params: InferInput<typeof ImsAuthParamsSchema>): Result<ImsAuthProvider, ImsAuthValidationError>;
58
+ /**
59
+ * Asserts the provided configuration for an {@link ImsAuthProvider}.
60
+ * @param config The configuration to validate.
61
+ * @throws {CommerceSdkValidationError} If the configuration is invalid.
62
+ * @example
63
+ * ```typescript
64
+ * const config = {
65
+ * clientId: "your-client-id",
66
+ * clientSecrets: ["your-client-secret"],
67
+ * technicalAccountId: "your-technical-account-id",
68
+ * technicalAccountEmail: "your-account@example.com",
69
+ * imsOrgId: "your-ims-org-id@AdobeOrg",
70
+ * scopes: ["AdobeID", "openid"],
71
+ * environment: "prod", // or "stage"
72
+ * context: "my-app-context"
73
+ * };
74
+ *
75
+ * // This will validate the config and throw if invalid
76
+ * assertImsAuthParams(config);
77
+ *```
78
+ * @example
79
+ * ```typescript
80
+ * // Example of a failing assert:
81
+ * try {
82
+ * assertImsAuthParams({
83
+ * clientId: "valid-client-id",
84
+ * // Missing required fields like clientSecrets, technicalAccountId, etc.
85
+ * });
86
+ * } catch (error) {
87
+ * console.error(error.message); // "Invalid ImsAuthProvider configuration"
88
+ * console.error(error.issues); // Array of validation issues
89
+ * }
90
+ * ```
91
+ */
92
+ declare function assertImsAuthParams(config: Record<PropertyKey, unknown>): asserts config is ImsAuthParams;
93
+ /**
94
+ * Creates an {@link ImsAuthProvider} based on the provided configuration.
95
+ * @param authParams An {@link ImsAuthParams} parameter that contains the configuration for the {@link ImsAuthProvider}.
96
+ * @returns An {@link ImsAuthProvider} instance that can be used to get access token and auth headers.
97
+ * @example
98
+ * ```typescript
99
+ * const config = {
100
+ * clientId: "your-client-id",
101
+ * clientSecrets: ["your-client-secret"],
102
+ * technicalAccountId: "your-technical-account-id",
103
+ * technicalAccountEmail: "your-account@example.com",
104
+ * imsOrgId: "your-ims-org-id@AdobeOrg",
105
+ * scopes: ["AdobeID", "openid"],
106
+ * environment: "prod",
107
+ * context: "my-app-context"
108
+ * };
109
+ *
110
+ * const authProvider = getImsAuthProvider(config);
111
+ *
112
+ * // Get access token
113
+ * const token = await authProvider.getAccessToken();
114
+ * console.log(token); // "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..."
115
+ *
116
+ * // Get headers for API requests
117
+ * const headers = await authProvider.getHeaders();
118
+ * console.log(headers);
119
+ * // {
120
+ * // Authorization: "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
121
+ * // "x-api-key": "your-client-id"
122
+ * // }
123
+ *
124
+ * // Use headers in API calls
125
+ * const response = await fetch('https://api.adobe.io/some-endpoint', {
126
+ * headers: await authProvider.getHeaders()
127
+ * });
128
+ * ```
129
+ */
130
+ declare function getImsAuthProvider(authParams: ImsAuthParams): {
131
+ getAccessToken: () => Promise<string>;
132
+ getHeaders: () => Promise<{
133
+ Authorization: string;
134
+ "x-api-key": string;
135
+ }>;
136
+ };
57
137
  //#endregion
58
138
  //#region source/lib/integration-auth/schema.d.ts
59
- declare const HttpMethodSchema: valibot0.PicklistSchema<readonly ["GET", "POST", "PUT", "PATCH", "DELETE"], undefined>;
60
- type HttpMethodInput = InferInput<typeof HttpMethodSchema>;
61
- declare const UrlSchema: valibot0.SchemaWithPipe<readonly [valibot0.UnionSchema<[valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<"Expected a string for the Adobe Commerce endpoint">, valibot0.NonEmptyAction<string, "Expected a non-empty string for the Adobe Commerce endpoint">, valibot0.UrlAction<string, "Expected a valid url for the Adobe Commerce endpoint">]>, valibot0.InstanceSchema<typeof url39.URL, undefined>], undefined>, valibot0.TransformAction<string | url39.URL, string>]>;
62
- type AdobeCommerceUri = InferInput<typeof UrlSchema>;
63
- declare const IntegrationAuthParamsSchema: valibot0.NonOptionalSchema<valibot0.ObjectSchema<{
64
- readonly AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
65
- readonly AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
66
- readonly AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
67
- readonly AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot0.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
139
+ /**
140
+ * The HTTP methods supported by Commerce.
141
+ * This is used to determine which headers to include in the signing of the authorization header.
142
+ */
143
+ type HttpMethodInput = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
144
+ /** Validation schema that accepts either a URL string or URL instance and normalizes to string. */
145
+
146
+ /**
147
+ * The schema for the Commerce Integration parameters.
148
+ * This is used to validate the parameters passed to the Commerce Integration provider.
149
+ */
150
+ declare const IntegrationAuthParamsSchema: valibot21.NonOptionalSchema<valibot21.ObjectSchema<{
151
+ readonly consumerKey: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
152
+ readonly consumerSecret: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
153
+ readonly accessToken: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
154
+ readonly accessTokenSecret: valibot21.SchemaWithPipe<readonly [valibot21.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot21.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
68
155
  }, undefined>, undefined>;
69
- type IntegrationAuthParams = InferInput<typeof IntegrationAuthParamsSchema>;
156
+ /** Defines the parameters required for Commerce Integration authentication. */
157
+ type IntegrationAuthParams = InferOutput<typeof IntegrationAuthParamsSchema>;
70
158
  //#endregion
71
159
  //#region source/lib/integration-auth/provider.d.ts
160
+ /** Defines the header key used for Commerce Integration authentication. */
72
161
  type IntegrationAuthHeader = "Authorization";
162
+ /** Defines the headers required for Commerce Integration authentication. */
73
163
  type IntegrationAuthHeaders = Record<IntegrationAuthHeader, string>;
74
- interface IntegrationConfig {
75
- consumerKey: string;
76
- consumerSecret: string;
77
- accessToken: string;
78
- accessTokenSecret: string;
79
- }
80
- type ValidationIssues = InferIssue<typeof IntegrationAuthParamsSchema>[] | InferIssue<typeof UrlSchema>[];
81
- type IntegrationAuthError = ValidationErrorType<"IntegrationAuthValidationError", ValidationIssues>;
164
+ /** Represents a URL for Adobe Commerce endpoints, accepting either string or URL object. */
165
+ type AdobeCommerceUrl = string | URL;
166
+ /** Defines an authentication provider for Adobe Commerce integrations. */
82
167
  interface IntegrationAuthProvider {
83
- getHeaders: (method: HttpMethodInput, url: AdobeCommerceUri) => Result<IntegrationAuthHeaders, IntegrationAuthError>;
168
+ getHeaders: (method: HttpMethodInput, url: AdobeCommerceUrl) => IntegrationAuthHeaders;
84
169
  }
85
- declare function getIntegrationAuthProvider(config: IntegrationConfig): IntegrationAuthProvider;
86
- declare function tryGetIntegrationAuthProvider(params: IntegrationAuthParams): Result<IntegrationAuthProvider, IntegrationAuthError>;
170
+ /**
171
+ * Asserts the provided configuration for an Adobe Commerce {@link IntegrationAuthProvider}.
172
+ * @param config The configuration to validate.
173
+ * @throws {CommerceSdkValidationError} If the configuration is invalid.
174
+ * @example
175
+ * ```typescript
176
+ * const config = {
177
+ * consumerKey: "your-consumer-key",
178
+ * consumerSecret: "your-consumer-secret",
179
+ * accessToken: "your-access-token",
180
+ * accessTokenSecret: "your-access-token-secret"
181
+ * };
182
+ *
183
+ * // This will validate the config and throw if invalid
184
+ * assertIntegrationAuthParams(config);
185
+ * ```
186
+ * @example
187
+ * ```typescript
188
+ * // Example of a failing assert:
189
+ * try {
190
+ * assertIntegrationAuthParams({
191
+ * consumerKey: "valid-consumer-key",
192
+ * // Missing required fields like consumerSecret, accessToken, accessTokenSecret
193
+ * });
194
+ * } catch (error) {
195
+ * console.error(error.message); // "Invalid IntegrationAuthProvider configuration"
196
+ * console.error(error.issues); // Array of validation issues
197
+ * }
198
+ * ```
199
+ */
200
+ declare function assertIntegrationAuthParams(config: Record<PropertyKey, unknown>): asserts config is IntegrationAuthParams;
201
+ /**
202
+ * Creates an {@link IntegrationAuthProvider} based on the provided configuration.
203
+ * @param authParams The configuration for the integration.
204
+ * @returns An {@link IntegrationAuthProvider} instance that can be used to get auth headers.
205
+ * @example
206
+ * ```typescript
207
+ * const config = {
208
+ * consumerKey: "your-consumer-key",
209
+ * consumerSecret: "your-consumer-secret",
210
+ * accessToken: "your-access-token",
211
+ * accessTokenSecret: "your-access-token-secret"
212
+ * };
213
+ *
214
+ * const authProvider = getIntegrationAuthProvider(config);
215
+ *
216
+ * // Get OAuth headers for a REST API call
217
+ * const headers = authProvider.getHeaders("GET", "https://your-store.com/rest/V1/products");
218
+ * console.log(headers); // { Authorization: "OAuth oauth_consumer_key=..., oauth_signature=..." }
219
+ *
220
+ * // Can also be used with URL objects
221
+ * const url = new URL("https://your-store.com/rest/V1/customers");
222
+ * const postHeaders = authProvider.getHeaders("POST", url);
223
+ * ```
224
+ */
225
+ declare function getIntegrationAuthProvider(authParams: IntegrationAuthParams): IntegrationAuthProvider;
87
226
  //#endregion
88
- export { IMS_AUTH_ENV, ImsAuthConfig, ImsAuthEnv, ImsAuthError, ImsAuthParams, ImsAuthProvider, IntegrationAuthError, IntegrationAuthParams, IntegrationAuthProvider, IntegrationConfig, getImsAuthProvider, getIntegrationAuthProvider, tryGetImsAuthProvider, tryGetIntegrationAuthProvider };
227
+ export { IMS_AUTH_ENV, type ImsAuthEnv, type ImsAuthParams, type ImsAuthProvider, type IntegrationAuthParams, type IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };