@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @adobe/aio-commerce-lib-auth
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`4b75585`](https://github.com/adobe/aio-commerce-sdk/commit/4b75585c0d27bd472de3277be5ddaf6a977664de)]:
8
+ - @adobe/aio-commerce-lib-core@0.4.0
9
+
10
+ ## 0.3.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#22](https://github.com/adobe/aio-commerce-sdk/pull/22) [`9885eee`](https://github.com/adobe/aio-commerce-sdk/commit/9885eee5849ba7939b2067d3357e677beced3774) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Changes include:
15
+ - Removed `try*` methods from public interface
16
+ - Added `assert` methods that throw if required configuration is not provided
17
+ - Cleaned up unused types to reduce bundle size
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [[`9885eee`](https://github.com/adobe/aio-commerce-sdk/commit/9885eee5849ba7939b2067d3357e677beced3774)]:
22
+ - @adobe/aio-commerce-lib-core@0.3.0
23
+
3
24
  ## 0.2.0
4
25
 
5
26
  ### Minor Changes
package/README.md CHANGED
@@ -7,120 +7,15 @@ Authentication utilities for Adobe Commerce apps deployed in Adobe App Builder.
7
7
 
8
8
  This library provides a unified interface for authentication in Adobe Commerce App Builder applications, supporting multiple authentication mechanisms required for different integration scenarios.
9
9
 
10
- ## Overview
11
-
12
- The library supports two main authentication providers:
13
-
14
- - **IMS Provider**: For authenticating users or services via Adobe Identity Management System (IMS) using OAuth2.
15
- - Required Params
16
- - AIO_COMMERCE_IMS_CLIENT_ID: string
17
- - AIO_COMMERCE_IMS_CLIENT_SECRETS: string
18
- - AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID: string
19
- - AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL: string
20
- - AIO_COMMERCE_IMS_IMS_ORG_ID: string
21
- - AIO_COMMERCE_IMS_ENV: string e.g `'prod'` or `'stage'`
22
- - AIO_COMMERCE_IMS_SCOPES: string e.g `'["value1", "value2"]'`
23
- - AIO_COMMERCE_IMS_CTX: string
24
- - **Integrations Provider**: For authenticating with Adobe Commerce integrations using OAuth 1.0a.
25
- - Required params
26
- - AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY: string
27
- - AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET: string
28
- - AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN: string
29
- - AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET: string
30
-
31
- These providers abstract the complexity of authentication, making it easy to obtain and use access tokens in your App Builder applications.
32
-
33
10
  ## Installation
34
11
 
35
12
  ```shell
36
- npm install @adobe/aio-commerce-lib-auth
13
+ pnpm install @adobe/aio-commerce-lib-auth
37
14
  ```
38
15
 
39
16
  ## Usage
40
17
 
41
- In your App Builder application, you can use the library to authenticate users or services and obtain access tokens.
42
-
43
- ### IMS Provider
44
-
45
- In the runtime action you can generate an access token using the IMS Provider:
46
-
47
- ```typescript
48
- import { tryGetImsAuthProvider } from "@adobe/aio-commerce-lib-auth";
49
- import { isErr, unwrap } from "@adobe/aio-commerce-lib-core";
50
-
51
- export const main = async function (params: Record<string, unknown>) {
52
- const result = tryGetImsAuthProvider(params); // Validate parameters and get the integration auth provider
53
-
54
- if (isErr(result)) {
55
- const { error } = result;
56
- return {
57
- statusCode: 400,
58
- body: {
59
- error: `Unable to get IMS Auth Provider ${error.message}`,
60
- },
61
- };
62
- }
63
-
64
- const imsAuthProvider = unwrap(result);
65
- const headersResult = imsAuthProvider.getHeaders();
66
-
67
- if (isErr(headersResult)) {
68
- const { error } = result;
69
- return {
70
- statusCode: 400,
71
- body: {
72
- error: `Unable to get auth headers for IMS Auth Provider ${error.message}`,
73
- },
74
- };
75
- }
76
-
77
- // business logic e.g requesting orders
78
- return { statusCode: 200 };
79
- };
80
- ```
81
-
82
- ### Integrations Provider
83
-
84
- In the runtime action you can generate an access token using the Integrations Provider:
85
-
86
- ```typescript
87
- import { tryGetIntegrationAuthProvider } from "@adobe/aio-commerce-lib-auth";
88
- import { isErr, unwrapErr, unwrap } from "@adobe/aio-commerce-lib-core";
89
-
90
- export const main = async function (params: Record<string, unknown>) {
91
- const result = tryGetIntegrationAuthProvider(params); // Validate parameters and get the integration auth provider
92
-
93
- if (isErr(result)) {
94
- const { error } = result;
95
- return {
96
- statusCode: 400,
97
- body: {
98
- error: `Unable to get Integration Auth Provider ${error.message}`,
99
- },
100
- };
101
- }
102
-
103
- const integrationsAuth = unwrap(result);
104
- const headersResult = integrationsAuth.getHeaders(
105
- "GET",
106
- "http://localhost/rest/V1/orders",
107
- );
108
-
109
- if (isErr(headersResult)) {
110
- const { error } = result;
111
- return {
112
- statusCode: 400,
113
- body: {
114
- error: `Unable to get auth headers for Integration Auth Provider ${error.message}`,
115
- },
116
- };
117
- }
118
-
119
- // business logic e.g requesting orders
120
-
121
- return { statusCode: 200 };
122
- };
123
- ```
18
+ See the [Usage Guide](./docs/usage.md) for more information.
124
19
 
125
20
  ## Contributing
126
21
 
@@ -1,61 +1,44 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
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
+ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from == "object" || typeof from == "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) key = keys[i], !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
16
19
  return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ }, __toESM = (mod, isNodeMode, target) => (target = mod == null ? {} : __create(__getProtoOf(mod)), __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
21
  value: mod,
20
- enumerable: true
22
+ enumerable: !0
21
23
  }) : target, mod));
22
-
23
- //#endregion
24
- const __adobe_aio_commerce_lib_core_result = __toESM(require("@adobe/aio-commerce-lib-core/result"));
25
- const __adobe_aio_lib_ims = __toESM(require("@adobe/aio-lib-ims"));
26
- const valibot = __toESM(require("valibot"));
27
- const node_crypto = __toESM(require("node:crypto"));
28
- const oauth_1_0a = __toESM(require("oauth-1.0a"));
29
-
30
- //#region source/lib/ims-auth/schema.ts
31
- const imsAuthParameter = (name) => (0, valibot.pipe)((0, valibot.string)(`Expected a string value for the IMS auth parameter ${name}`), (0, valibot.nonEmpty)(`Expected a non-empty string value for the IMS auth parameter ${name}`));
32
- const jsonStringArray = (name) => {
33
- const jsonStringArraySchema = (0, valibot.message)((0, valibot.pipe)((0, valibot.string)(`Expected a string value for the IMS auth parameter ${name}`), (0, valibot.nonEmpty)(`Expected a non-empty string value for the IMS auth parameter ${name}`), (0, valibot.parseJson)()), `An error occurred while parsing the JSON string array parameter ${name}`);
34
- return (0, valibot.pipe)(jsonStringArraySchema, (0, valibot.array)((0, valibot.string)(), `Expected a stringified JSON array value for the IMS auth parameter ${name}`));
35
- };
36
- /** The environments accepted by the IMS auth service. */
37
- const IMS_AUTH_ENV = {
24
+ const __adobe_aio_commerce_lib_core_error = __toESM(require("@adobe/aio-commerce-lib-core/error")), __adobe_aio_lib_ims = __toESM(require("@adobe/aio-lib-ims")), valibot = __toESM(require("valibot")), crypto = __toESM(require("crypto")), oauth_1_0a = __toESM(require("oauth-1.0a")), imsAuthParameter = (name) => (0, valibot.pipe)((0, valibot.string)(`Expected a string value for the IMS auth parameter ${name}`), (0, valibot.nonEmpty)(`Expected a non-empty string value for the IMS auth parameter ${name}`)), stringArray = (name) => (0, valibot.pipe)((0, valibot.array)((0, valibot.string)(), `Expected a stringified JSON array value for the IMS auth parameter ${name}`)), IMS_AUTH_ENV = {
38
25
  PROD: "prod",
39
26
  STAGE: "stage"
40
- };
41
- const ImsAuthEnvSchema = (0, valibot.enum)(IMS_AUTH_ENV);
42
- /** Defines the schema to validate the necessary parameters for the IMS auth service. */
43
- const ImsAuthParamsSchema = (0, valibot.object)({
44
- AIO_COMMERCE_IMS_CLIENT_ID: imsAuthParameter("AIO_COMMERCE_IMS_CLIENT_ID"),
45
- AIO_COMMERCE_IMS_CLIENT_SECRETS: jsonStringArray("AIO_COMMERCE_IMS_CLIENT_SECRETS"),
46
- AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID: imsAuthParameter("AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID"),
47
- AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL: imsAuthParameter("AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL"),
48
- AIO_COMMERCE_IMS_IMS_ORG_ID: imsAuthParameter("AIO_COMMERCE_IMS_IMS_ORG_ID"),
49
- AIO_COMMERCE_IMS_ENV: (0, valibot.pipe)((0, valibot.optional)(ImsAuthEnvSchema, IMS_AUTH_ENV.PROD)),
50
- AIO_COMMERCE_IMS_CTX: (0, valibot.pipe)((0, valibot.optional)((0, valibot.string)(), "aio-commerce-sdk-creds")),
51
- AIO_COMMERCE_IMS_SCOPES: jsonStringArray("AIO_COMMERCE_IMS_SCOPES")
27
+ }, ImsAuthEnvSchema = (0, valibot.enum)(IMS_AUTH_ENV), ImsAuthParamsSchema = (0, valibot.object)({
28
+ clientId: imsAuthParameter("clientId"),
29
+ clientSecrets: (0, valibot.pipe)(stringArray("clientSecrets"), (0, valibot.minLength)(1, "Expected at least one client secret for IMS auth")),
30
+ technicalAccountId: imsAuthParameter("technicalAccountId"),
31
+ technicalAccountEmail: (0, valibot.pipe)((0, valibot.string)("Expected a string value for the IMS auth parameter technicalAccountEmail"), (0, valibot.email)("Expected a valid email format for technicalAccountEmail")),
32
+ imsOrgId: imsAuthParameter("imsOrgId"),
33
+ environment: (0, valibot.pipe)((0, valibot.optional)(ImsAuthEnvSchema, IMS_AUTH_ENV.PROD)),
34
+ context: (0, valibot.pipe)((0, valibot.optional)((0, valibot.string)(), "aio-commerce-sdk-creds")),
35
+ scopes: (0, valibot.pipe)(stringArray("scopes"), (0, valibot.minLength)(1, "Expected at least one scope for IMS auth"))
52
36
  });
53
-
54
- //#endregion
55
- //#region source/lib/ims-auth/provider.ts
56
- function snakeCaseImsAuthConfig(config) {
37
+ function toImsAuthConfig(config) {
57
38
  return {
58
- ...config,
39
+ scopes: config.scopes,
40
+ env: config?.environment ?? "prod",
41
+ context: config.context,
59
42
  client_id: config.clientId,
60
43
  client_secrets: config.clientSecrets,
61
44
  technical_account_id: config.technicalAccountId,
@@ -63,166 +46,54 @@ function snakeCaseImsAuthConfig(config) {
63
46
  ims_org_id: config.imsOrgId
64
47
  };
65
48
  }
66
- function makeImsAuthValidationError(message, issues) {
67
- return {
68
- _tag: "ImsAuthValidationError",
69
- message,
70
- issues
71
- };
72
- }
73
- function makeImsAuthError(message, error) {
74
- return {
75
- _tag: "ImsAuthError",
76
- message,
77
- error
78
- };
79
- }
80
- function fromParams$1(params) {
81
- return {
82
- clientId: params.AIO_COMMERCE_IMS_CLIENT_ID,
83
- clientSecrets: params.AIO_COMMERCE_IMS_CLIENT_SECRETS,
84
- technicalAccountId: params.AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID,
85
- technicalAccountEmail: params.AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL,
86
- imsOrgId: params.AIO_COMMERCE_IMS_IMS_ORG_ID,
87
- scopes: params.AIO_COMMERCE_IMS_SCOPES,
88
- environment: params.AIO_COMMERCE_IMS_ENV,
89
- context: params.AIO_COMMERCE_IMS_CTX
90
- };
91
- }
92
- async function tryGetAccessToken(contextName) {
93
- try {
94
- const accessToken = await (0, __adobe_aio_lib_ims.getToken)(contextName, {});
95
- return (0, __adobe_aio_commerce_lib_core_result.ok)(accessToken);
96
- } catch (error) {
97
- return (0, __adobe_aio_commerce_lib_core_result.err)(makeImsAuthError("Failed to retrieve IMS access token", error));
98
- }
49
+ function assertImsAuthParams(config) {
50
+ let result = (0, valibot.safeParse)(ImsAuthParamsSchema, config);
51
+ if (!result.success) throw new __adobe_aio_commerce_lib_core_error.CommerceSdkValidationError("Invalid ImsAuthProvider configuration", { issues: result.issues });
99
52
  }
100
- /**
101
- * Creates an {@link ImsAuthProvider} based on the provided configuration.
102
- * @param config The configuration for the IMS Auth Provider.
103
- * @returns An {@link ImsAuthProvider} instance that can be used to get access token and auth headers.
104
- */
105
- function getImsAuthProvider(config) {
106
- const getAccessToken = async () => {
107
- const snakeCasedConfig = snakeCaseImsAuthConfig(config);
108
- await __adobe_aio_lib_ims.context.set(config.context, snakeCasedConfig);
109
- return tryGetAccessToken(config.context);
110
- };
111
- const getHeaders = async () => {
112
- const result = await getAccessToken();
113
- return (0, __adobe_aio_commerce_lib_core_result.map)(result, (accessToken) => ({
53
+ function getImsAuthProvider(authParams) {
54
+ let getAccessToken = async () => {
55
+ let imsAuthConfig = toImsAuthConfig(authParams);
56
+ return await __adobe_aio_lib_ims.context.set(authParams.context, imsAuthConfig), (0, __adobe_aio_lib_ims.getToken)(authParams.context, {});
57
+ }, getHeaders = async () => {
58
+ let accessToken = await getAccessToken();
59
+ return {
114
60
  Authorization: `Bearer ${accessToken}`,
115
- "x-api-key": config.clientId
116
- }));
61
+ "x-api-key": authParams.clientId
62
+ };
117
63
  };
118
64
  return {
119
65
  getAccessToken,
120
66
  getHeaders
121
67
  };
122
68
  }
123
- /**
124
- * Tries to create an {@link ImsAuthProvider} based on the provided parameters.
125
- * @param params The parameters required to create the IMS Auth Provider.
126
- * @returns An {@link ImsAuthProvider} instance that can be used to get access token and auth headers.
127
- */
128
- function tryGetImsAuthProvider(params) {
129
- const validation = (0, valibot.safeParse)(ImsAuthParamsSchema, params);
130
- if (!validation.success) return (0, __adobe_aio_commerce_lib_core_result.err)(makeImsAuthValidationError("Failed to validate the provided IMS parameters", validation.issues));
131
- return (0, __adobe_aio_commerce_lib_core_result.ok)(getImsAuthProvider(fromParams$1(validation.output)));
132
- }
133
-
134
- //#endregion
135
- //#region source/lib/integration-auth/schema.ts
136
- /**
137
- * The HTTP methods supported by Commerce.
138
- * This is used to determine which headers to include in the signing of the authorization header.
139
- */
140
- const AllowedHttpMethod = [
141
- "GET",
142
- "POST",
143
- "PUT",
144
- "PATCH",
145
- "DELETE"
146
- ];
147
- const HttpMethodSchema = (0, valibot.picklist)(AllowedHttpMethod);
148
- const integrationAuthParameter = (name) => (0, valibot.pipe)((0, valibot.string)(`Expected a string value for the Commerce Integration parameter ${name}`), (0, valibot.nonEmpty)(`Expected a non-empty string value for the Commerce Integration parameter ${name}`));
149
- const BaseUrlSchema = (0, valibot.pipe)((0, valibot.string)("Expected a string for the Adobe Commerce endpoint"), (0, valibot.nonEmpty)("Expected a non-empty string for the Adobe Commerce endpoint"), (0, valibot.url)("Expected a valid url for the Adobe Commerce endpoint"));
150
- const UrlSchema = (0, valibot.pipe)((0, valibot.union)([BaseUrlSchema, (0, valibot.instance)(URL)]), (0, valibot.transform)((url) => {
151
- if (url instanceof URL) return url.toString();
152
- return url;
153
- }));
154
- /**
155
- * The schema for the Commerce Integration parameters.
156
- * This is used to validate the parameters passed to the Commerce Integration provider.
157
- */
158
- const IntegrationAuthParamsSchema = (0, valibot.nonOptional)((0, valibot.object)({
159
- AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY: integrationAuthParameter("AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY"),
160
- AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET: integrationAuthParameter("AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET"),
161
- AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN: integrationAuthParameter("AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN"),
162
- AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET: integrationAuthParameter("AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET")
69
+ const integrationAuthParameter = (name) => (0, valibot.pipe)((0, valibot.string)(`Expected a string value for the Commerce Integration parameter ${name}`), (0, valibot.nonEmpty)(`Expected a non-empty string value for the Commerce Integration parameter ${name}`)), BaseUrlSchema = (0, valibot.pipe)((0, valibot.string)("Expected a string for the Adobe Commerce endpoint"), (0, valibot.nonEmpty)("Expected a non-empty string for the Adobe Commerce endpoint"), (0, valibot.url)("Expected a valid url for the Adobe Commerce endpoint")), UrlSchema = (0, valibot.pipe)((0, valibot.union)([BaseUrlSchema, (0, valibot.instance)(URL)]), (0, valibot.transform)((url) => url instanceof URL ? url.toString() : url)), IntegrationAuthParamsSchema = (0, valibot.nonOptional)((0, valibot.object)({
70
+ consumerKey: integrationAuthParameter("consumerKey"),
71
+ consumerSecret: integrationAuthParameter("consumerSecret"),
72
+ accessToken: integrationAuthParameter("accessToken"),
73
+ accessTokenSecret: integrationAuthParameter("accessTokenSecret")
163
74
  }));
164
-
165
- //#endregion
166
- //#region source/lib/integration-auth/provider.ts
167
- function makeIntegrationAuthValidationError(message, issues) {
168
- return {
169
- _tag: "IntegrationAuthValidationError",
170
- message,
171
- issues
172
- };
75
+ function assertIntegrationAuthParams(config) {
76
+ let result = (0, valibot.safeParse)(IntegrationAuthParamsSchema, config);
77
+ if (!result.success) throw new __adobe_aio_commerce_lib_core_error.CommerceSdkValidationError("Invalid IntegrationAuthProvider configuration", { issues: result.issues });
173
78
  }
174
- function fromParams(params) {
175
- return {
176
- consumerKey: params.AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY,
177
- consumerSecret: params.AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET,
178
- accessToken: params.AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN,
179
- accessTokenSecret: params.AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET
180
- };
181
- }
182
- /**
183
- * Creates an {@link IntegrationAuthProvider} based on the provided configuration.
184
- * @param config The configuration for the integration.
185
- * @returns An {@link IntegrationAuthProvider} instance that can be used to get auth headers.
186
- */
187
- function getIntegrationAuthProvider(config) {
188
- const oauth = new oauth_1_0a.default({
79
+ function getIntegrationAuthProvider(authParams) {
80
+ let oauth = new oauth_1_0a.default({
189
81
  consumer: {
190
- key: config.consumerKey,
191
- secret: config.consumerSecret
82
+ key: authParams.consumerKey,
83
+ secret: authParams.consumerSecret
192
84
  },
193
85
  signature_method: "HMAC-SHA256",
194
- hash_function: (baseString, key) => node_crypto.default.createHmac("sha256", key).update(baseString).digest("base64")
195
- });
196
- const oauthToken = {
197
- key: config.accessToken,
198
- secret: config.accessTokenSecret
86
+ hash_function: (baseString, key) => crypto.default.createHmac("sha256", key).update(baseString).digest("base64")
87
+ }), oauthToken = {
88
+ key: authParams.accessToken,
89
+ secret: authParams.accessTokenSecret
199
90
  };
200
- const getHeaders = (method, url) => {
201
- const uriValidation = (0, valibot.safeParse)(UrlSchema, url);
202
- if (!uriValidation.success) return (0, __adobe_aio_commerce_lib_core_result.err)(makeIntegrationAuthValidationError("Failed to validate the provided Adobe Commerce URL", uriValidation.issues));
203
- const finalUrl = uriValidation.output;
204
- const headers = oauth.toHeader(oauth.authorize({
205
- url: finalUrl,
91
+ return { getHeaders: (method, url) => {
92
+ let urlString = url instanceof URL ? url.toString() : url;
93
+ return oauth.toHeader(oauth.authorize({
94
+ url: urlString,
206
95
  method
207
96
  }, oauthToken));
208
- return (0, __adobe_aio_commerce_lib_core_result.ok)(headers);
209
- };
210
- return { getHeaders };
211
- }
212
- /**
213
- * Tries to create an {@link IntegrationAuthProvider} based on the provided parameters.
214
- * @param params The parameters required for integration authentication.
215
- * @returns An {@link IntegrationAuthProvider} instance that can be used to get auth headers.
216
- */
217
- function tryGetIntegrationAuthProvider(params) {
218
- const validation = (0, valibot.safeParse)(IntegrationAuthParamsSchema, params);
219
- if (!validation.success) return (0, __adobe_aio_commerce_lib_core_result.err)(makeIntegrationAuthValidationError("Failed to validate the provided integration parameters", validation.issues));
220
- return (0, __adobe_aio_commerce_lib_core_result.ok)(getIntegrationAuthProvider(fromParams(validation.output)));
97
+ } };
221
98
  }
222
-
223
- //#endregion
224
- exports.IMS_AUTH_ENV = IMS_AUTH_ENV;
225
- exports.getImsAuthProvider = getImsAuthProvider;
226
- exports.getIntegrationAuthProvider = getIntegrationAuthProvider;
227
- exports.tryGetImsAuthProvider = tryGetImsAuthProvider;
228
- exports.tryGetIntegrationAuthProvider = tryGetIntegrationAuthProvider;
99
+ exports.IMS_AUTH_ENV = IMS_AUTH_ENV, exports.assertImsAuthParams = assertImsAuthParams, exports.assertIntegrationAuthParams = assertIntegrationAuthParams, exports.getImsAuthProvider = getImsAuthProvider, exports.getIntegrationAuthProvider = getIntegrationAuthProvider;