@adobe/aio-commerce-lib-auth 0.3.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @adobe/aio-commerce-lib-auth
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#95](https://github.com/adobe/aio-commerce-sdk/pull/95) [`abd5012`](https://github.com/adobe/aio-commerce-sdk/commit/abd5012e5680f97abd150de6036b2225c7dc0277) Thanks [@iivvaannxx](https://github.com/apps/renovate)! - [Breaking] Ensure `UrlSchema` is used when validating the input URL of Commerce Integration Auth. Now, if the input URL is not in the expected format it will throw.
8
+
9
+ ## 0.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#81](https://github.com/adobe/aio-commerce-sdk/pull/81) [`e0db24c`](https://github.com/adobe/aio-commerce-sdk/commit/e0db24c04aed9a6df72e80d5395aa41374570b6a) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Remove `IMS_AUTH_ENV` enum and replace it with a simple union. Remove default value from `environment` in `ImsAuthParams` as `prod` is used by default.
14
+
3
15
  ## 0.3.4
4
16
 
5
17
  ### Patch Changes
@@ -11,89 +11,4 @@
11
11
  * OF ANY KIND, either express or implied. See the License for the specific language
12
12
  * governing permissions and limitations under the License.
13
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
- });
19
- return to;
20
- }, __toESM = (mod, isNodeMode, target) => (target = mod == null ? {} : __create(__getProtoOf(mod)), __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
- value: mod,
22
- enumerable: !0
23
- }) : target, mod));
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 string array value for the IMS auth parameter ${name}`)), IMS_AUTH_ENV = {
25
- PROD: "prod",
26
- STAGE: "stage"
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)())),
35
- scopes: (0, valibot.pipe)(stringArray("scopes"), (0, valibot.minLength)(1, "Expected at least one scope for IMS auth"))
36
- }), { context, getToken } = __adobe_aio_lib_ims.default;
37
- function toImsAuthConfig(config) {
38
- return {
39
- scopes: config.scopes,
40
- env: config?.environment ?? "prod",
41
- context: config.context ?? "aio-commerce-lib-auth-creds",
42
- client_id: config.clientId,
43
- client_secrets: config.clientSecrets,
44
- technical_account_id: config.technicalAccountId,
45
- technical_account_email: config.technicalAccountEmail,
46
- ims_org_id: config.imsOrgId
47
- };
48
- }
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 });
52
- }
53
- function getImsAuthProvider(authParams) {
54
- let getAccessToken = async () => {
55
- let imsAuthConfig = toImsAuthConfig(authParams);
56
- return await context.set(imsAuthConfig.context, imsAuthConfig), getToken(imsAuthConfig.context, {});
57
- }, getHeaders = async () => {
58
- let accessToken = await getAccessToken();
59
- return {
60
- Authorization: `Bearer ${accessToken}`,
61
- "x-api-key": authParams.clientId
62
- };
63
- };
64
- return {
65
- getAccessToken,
66
- getHeaders
67
- };
68
- }
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")
74
- }));
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 });
78
- }
79
- function getIntegrationAuthProvider(authParams) {
80
- let oauth = new oauth_1_0a.default({
81
- consumer: {
82
- key: authParams.consumerKey,
83
- secret: authParams.consumerSecret
84
- },
85
- signature_method: "HMAC-SHA256",
86
- hash_function: (baseString, key) => crypto.default.createHmac("sha256", key).update(baseString).digest("base64")
87
- }), oauthToken = {
88
- key: authParams.accessToken,
89
- secret: authParams.accessTokenSecret
90
- };
91
- return { getHeaders: (method, url) => {
92
- let urlString = url instanceof URL ? url.toString() : url;
93
- return oauth.toHeader(oauth.authorize({
94
- url: urlString,
95
- method
96
- }, oauthToken));
97
- } };
98
- }
99
- exports.IMS_AUTH_ENV = IMS_AUTH_ENV, exports.assertImsAuthParams = assertImsAuthParams, exports.assertIntegrationAuthParams = assertIntegrationAuthParams, exports.getImsAuthProvider = getImsAuthProvider, exports.getIntegrationAuthProvider = getIntegrationAuthProvider;
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)=>{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,{get:(k=>from[k]).bind(null,key),enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to},__toESM=(mod,isNodeMode,target)=>(target=mod==null?{}:__create(__getProtoOf(mod)),__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,`default`,{value:mod,enumerable:!0}):target,mod));let __adobe_aio_commerce_lib_core_error=require(`@adobe/aio-commerce-lib-core/error`);__adobe_aio_commerce_lib_core_error=__toESM(__adobe_aio_commerce_lib_core_error);let __adobe_aio_lib_ims=require(`@adobe/aio-lib-ims`);__adobe_aio_lib_ims=__toESM(__adobe_aio_lib_ims);let valibot=require(`valibot`);valibot=__toESM(valibot);let crypto=require(`crypto`);crypto=__toESM(crypto);let oauth_1_0a=require(`oauth-1.0a`);oauth_1_0a=__toESM(oauth_1_0a);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}`)),stringArray=name=>(0,valibot.pipe)((0,valibot.array)((0,valibot.string)(),`Expected a string array value for the IMS auth parameter ${name}`)),ImsAuthEnvSchema=(0,valibot.picklist)([`prod`,`stage`]),ImsAuthParamsSchema=(0,valibot.object)({clientId:imsAuthParameter(`clientId`),clientSecrets:(0,valibot.pipe)(stringArray(`clientSecrets`),(0,valibot.minLength)(1,`Expected at least one client secret for IMS auth`)),technicalAccountId:imsAuthParameter(`technicalAccountId`),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`)),imsOrgId:imsAuthParameter(`imsOrgId`),environment:(0,valibot.pipe)((0,valibot.optional)(ImsAuthEnvSchema)),context:(0,valibot.pipe)((0,valibot.optional)((0,valibot.string)())),scopes:(0,valibot.pipe)(stringArray(`scopes`),(0,valibot.minLength)(1,`Expected at least one scope for IMS auth`))}),{context,getToken}=__adobe_aio_lib_ims.default;function toImsAuthConfig(config){return{scopes:config.scopes,env:config?.environment??`prod`,context:config.context??`aio-commerce-lib-auth-creds`,client_id:config.clientId,client_secrets:config.clientSecrets,technical_account_id:config.technicalAccountId,technical_account_email:config.technicalAccountEmail,ims_org_id:config.imsOrgId}}function assertImsAuthParams(config){let result=(0,valibot.safeParse)(ImsAuthParamsSchema,config);if(!result.success)throw new __adobe_aio_commerce_lib_core_error.CommerceSdkValidationError(`Invalid ImsAuthProvider configuration`,{issues:result.issues})}function getImsAuthProvider(authParams){let getAccessToken=async()=>{let imsAuthConfig=toImsAuthConfig(authParams);return await context.set(imsAuthConfig.context,imsAuthConfig),getToken(imsAuthConfig.context,{})};return{getAccessToken,getHeaders:async()=>({Authorization:`Bearer ${await getAccessToken()}`,"x-api-key":authParams.clientId})}}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)({consumerKey:integrationAuthParameter(`consumerKey`),consumerSecret:integrationAuthParameter(`consumerSecret`),accessToken:integrationAuthParameter(`accessToken`),accessTokenSecret:integrationAuthParameter(`accessTokenSecret`)}));function assertIntegrationAuthParams(config){let result=(0,valibot.safeParse)(IntegrationAuthParamsSchema,config);if(!result.success)throw new __adobe_aio_commerce_lib_core_error.CommerceSdkValidationError(`Invalid IntegrationAuthProvider configuration`,{issues:result.issues})}function getIntegrationAuthProvider(authParams){let oauth=new oauth_1_0a.default({consumer:{key:authParams.consumerKey,secret:authParams.consumerSecret},signature_method:`HMAC-SHA256`,hash_function:(baseString,key)=>crypto.default.createHmac(`sha256`,key).update(baseString).digest(`base64`)}),oauthToken={key:authParams.accessToken,secret:authParams.accessTokenSecret};return{getHeaders:(method,url)=>{let urlString=(0,valibot.parse)(UrlSchema,url);return oauth.toHeader(oauth.authorize({url:urlString,method},oauthToken))}}}exports.assertImsAuthParams=assertImsAuthParams,exports.assertIntegrationAuthParams=assertIntegrationAuthParams,exports.getImsAuthProvider=getImsAuthProvider,exports.getIntegrationAuthProvider=getIntegrationAuthProvider;
@@ -16,16 +16,8 @@ import * as valibot21 from "valibot";
16
16
  import { InferOutput } from "valibot";
17
17
 
18
18
  //#region source/lib/ims-auth/schema.d.ts
19
- /** The environments accepted by the IMS auth service. */
20
- declare const IMS_AUTH_ENV: {
21
- readonly PROD: "prod";
22
- readonly STAGE: "stage";
23
- };
24
19
  /** Validation schema for IMS auth environment values. */
25
- declare const ImsAuthEnvSchema: valibot21.EnumSchema<{
26
- readonly PROD: "prod";
27
- readonly STAGE: "stage";
28
- }, undefined>;
20
+ declare const ImsAuthEnvSchema: valibot21.PicklistSchema<["prod", "stage"], undefined>;
29
21
  /** Defines the schema to validate the necessary parameters for the IMS auth service. */
30
22
  declare const ImsAuthParamsSchema: valibot21.ObjectSchema<{
31
23
  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}`>]>;
@@ -33,10 +25,7 @@ declare const ImsAuthParamsSchema: valibot21.ObjectSchema<{
33
25
  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
26
  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
27
  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<{
37
- readonly PROD: "prod";
38
- readonly STAGE: "stage";
39
- }, undefined>, "prod">]>;
28
+ readonly environment: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.PicklistSchema<["prod", "stage"], undefined>, undefined>]>;
40
29
  readonly context: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.StringSchema<undefined>, undefined>]>;
41
30
  readonly scopes: valibot21.SchemaWithPipe<readonly [valibot21.SchemaWithPipe<readonly [valibot21.ArraySchema<valibot21.StringSchema<undefined>, `Expected a string array value for the IMS auth parameter ${string}`>]>, valibot21.MinLengthAction<string[], 1, "Expected at least one scope for IMS auth">]>;
42
31
  }, undefined>;
@@ -141,8 +130,6 @@ declare function getImsAuthProvider(authParams: ImsAuthParams): {
141
130
  * This is used to determine which headers to include in the signing of the authorization header.
142
131
  */
143
132
  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
133
  /**
147
134
  * The schema for the Commerce Integration parameters.
148
135
  * This is used to validate the parameters passed to the Commerce Integration provider.
@@ -224,4 +211,4 @@ declare function assertIntegrationAuthParams(config: Record<PropertyKey, unknown
224
211
  */
225
212
  declare function getIntegrationAuthProvider(authParams: IntegrationAuthParams): IntegrationAuthProvider;
226
213
  //#endregion
227
- export { IMS_AUTH_ENV, type ImsAuthEnv, type ImsAuthParams, type ImsAuthProvider, type IntegrationAuthParams, type IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
214
+ export { type ImsAuthEnv, type ImsAuthParams, type ImsAuthProvider, type IntegrationAuthParams, type IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
@@ -12,33 +12,22 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
- import * as valibot21 from "valibot";
15
+ import * as valibot0 from "valibot";
16
16
  import { InferOutput } from "valibot";
17
17
 
18
18
  //#region source/lib/ims-auth/schema.d.ts
19
- /** The environments accepted by the IMS auth service. */
20
- declare const IMS_AUTH_ENV: {
21
- readonly PROD: "prod";
22
- readonly STAGE: "stage";
23
- };
24
19
  /** Validation schema for IMS auth environment values. */
25
- declare const ImsAuthEnvSchema: valibot21.EnumSchema<{
26
- readonly PROD: "prod";
27
- readonly STAGE: "stage";
28
- }, undefined>;
20
+ declare const ImsAuthEnvSchema: valibot0.PicklistSchema<["prod", "stage"], undefined>;
29
21
  /** 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 string 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<{
37
- readonly PROD: "prod";
38
- readonly STAGE: "stage";
39
- }, undefined>, "prod">]>;
40
- readonly context: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.StringSchema<undefined>, undefined>]>;
41
- readonly scopes: valibot21.SchemaWithPipe<readonly [valibot21.SchemaWithPipe<readonly [valibot21.ArraySchema<valibot21.StringSchema<undefined>, `Expected a string array value for the IMS auth parameter ${string}`>]>, valibot21.MinLengthAction<string[], 1, "Expected at least one scope for IMS auth">]>;
22
+ declare const ImsAuthParamsSchema: valibot0.ObjectSchema<{
23
+ readonly clientId: 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}`>]>;
24
+ readonly clientSecrets: valibot0.SchemaWithPipe<readonly [valibot0.SchemaWithPipe<readonly [valibot0.ArraySchema<valibot0.StringSchema<undefined>, `Expected a string array value for the IMS auth parameter ${string}`>]>, valibot0.MinLengthAction<string[], 1, "Expected at least one client secret for IMS auth">]>;
25
+ readonly technicalAccountId: 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}`>]>;
26
+ readonly technicalAccountEmail: valibot0.SchemaWithPipe<readonly [valibot0.StringSchema<"Expected a string value for the IMS auth parameter technicalAccountEmail">, valibot0.EmailAction<string, "Expected a valid email format for technicalAccountEmail">]>;
27
+ readonly imsOrgId: 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}`>]>;
28
+ readonly environment: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.PicklistSchema<["prod", "stage"], undefined>, undefined>]>;
29
+ readonly context: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.StringSchema<undefined>, undefined>]>;
30
+ readonly scopes: valibot0.SchemaWithPipe<readonly [valibot0.SchemaWithPipe<readonly [valibot0.ArraySchema<valibot0.StringSchema<undefined>, `Expected a string array value for the IMS auth parameter ${string}`>]>, valibot0.MinLengthAction<string[], 1, "Expected at least one scope for IMS auth">]>;
42
31
  }, undefined>;
43
32
  /** Defines the parameters for the IMS auth service. */
44
33
  type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
@@ -141,17 +130,15 @@ declare function getImsAuthProvider(authParams: ImsAuthParams): {
141
130
  * This is used to determine which headers to include in the signing of the authorization header.
142
131
  */
143
132
  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
133
  /**
147
134
  * The schema for the Commerce Integration parameters.
148
135
  * This is used to validate the parameters passed to the Commerce Integration provider.
149
136
  */
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}`>]>;
137
+ declare const IntegrationAuthParamsSchema: valibot0.NonOptionalSchema<valibot0.ObjectSchema<{
138
+ readonly consumerKey: 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
+ readonly consumerSecret: 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}`>]>;
140
+ readonly accessToken: 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}`>]>;
141
+ readonly accessTokenSecret: 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}`>]>;
155
142
  }, undefined>, undefined>;
156
143
  /** Defines the parameters required for Commerce Integration authentication. */
157
144
  type IntegrationAuthParams = InferOutput<typeof IntegrationAuthParamsSchema>;
@@ -224,4 +211,4 @@ declare function assertIntegrationAuthParams(config: Record<PropertyKey, unknown
224
211
  */
225
212
  declare function getIntegrationAuthProvider(authParams: IntegrationAuthParams): IntegrationAuthProvider;
226
213
  //#endregion
227
- export { IMS_AUTH_ENV, type ImsAuthEnv, type ImsAuthParams, type ImsAuthProvider, type IntegrationAuthParams, type IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
214
+ export { type ImsAuthEnv, type ImsAuthParams, type ImsAuthProvider, type IntegrationAuthParams, type IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
package/dist/es/index.js CHANGED
@@ -11,86 +11,4 @@
11
11
  * OF ANY KIND, either express or implied. See the License for the specific language
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
- import { CommerceSdkValidationError } from "@adobe/aio-commerce-lib-core/error";
15
- import aioLibIms from "@adobe/aio-lib-ims";
16
- import { array, email, enum as enum$1, instance, minLength, nonEmpty, nonOptional, object, optional, pipe, safeParse, string, transform, union, url } from "valibot";
17
- import crypto from "crypto";
18
- import OAuth1a from "oauth-1.0a";
19
- const imsAuthParameter = (name) => pipe(string(`Expected a string value for the IMS auth parameter ${name}`), nonEmpty(`Expected a non-empty string value for the IMS auth parameter ${name}`)), stringArray = (name) => pipe(array(string(), `Expected a string array value for the IMS auth parameter ${name}`)), IMS_AUTH_ENV = {
20
- PROD: "prod",
21
- STAGE: "stage"
22
- }, ImsAuthEnvSchema = enum$1(IMS_AUTH_ENV), ImsAuthParamsSchema = object({
23
- clientId: imsAuthParameter("clientId"),
24
- clientSecrets: pipe(stringArray("clientSecrets"), minLength(1, "Expected at least one client secret for IMS auth")),
25
- technicalAccountId: imsAuthParameter("technicalAccountId"),
26
- technicalAccountEmail: pipe(string("Expected a string value for the IMS auth parameter technicalAccountEmail"), email("Expected a valid email format for technicalAccountEmail")),
27
- imsOrgId: imsAuthParameter("imsOrgId"),
28
- environment: pipe(optional(ImsAuthEnvSchema, IMS_AUTH_ENV.PROD)),
29
- context: pipe(optional(string())),
30
- scopes: pipe(stringArray("scopes"), minLength(1, "Expected at least one scope for IMS auth"))
31
- }), { context, getToken } = aioLibIms;
32
- function toImsAuthConfig(config) {
33
- return {
34
- scopes: config.scopes,
35
- env: config?.environment ?? "prod",
36
- context: config.context ?? "aio-commerce-lib-auth-creds",
37
- client_id: config.clientId,
38
- client_secrets: config.clientSecrets,
39
- technical_account_id: config.technicalAccountId,
40
- technical_account_email: config.technicalAccountEmail,
41
- ims_org_id: config.imsOrgId
42
- };
43
- }
44
- function assertImsAuthParams(config) {
45
- let result = safeParse(ImsAuthParamsSchema, config);
46
- if (!result.success) throw new CommerceSdkValidationError("Invalid ImsAuthProvider configuration", { issues: result.issues });
47
- }
48
- function getImsAuthProvider(authParams) {
49
- let getAccessToken = async () => {
50
- let imsAuthConfig = toImsAuthConfig(authParams);
51
- return await context.set(imsAuthConfig.context, imsAuthConfig), getToken(imsAuthConfig.context, {});
52
- }, getHeaders = async () => {
53
- let accessToken = await getAccessToken();
54
- return {
55
- Authorization: `Bearer ${accessToken}`,
56
- "x-api-key": authParams.clientId
57
- };
58
- };
59
- return {
60
- getAccessToken,
61
- getHeaders
62
- };
63
- }
64
- const integrationAuthParameter = (name) => pipe(string(`Expected a string value for the Commerce Integration parameter ${name}`), nonEmpty(`Expected a non-empty string value for the Commerce Integration parameter ${name}`)), BaseUrlSchema = pipe(string("Expected a string for the Adobe Commerce endpoint"), nonEmpty("Expected a non-empty string for the Adobe Commerce endpoint"), url("Expected a valid url for the Adobe Commerce endpoint"));
65
- pipe(union([BaseUrlSchema, instance(URL)]), transform((url$1) => url$1 instanceof URL ? url$1.toString() : url$1));
66
- const IntegrationAuthParamsSchema = nonOptional(object({
67
- consumerKey: integrationAuthParameter("consumerKey"),
68
- consumerSecret: integrationAuthParameter("consumerSecret"),
69
- accessToken: integrationAuthParameter("accessToken"),
70
- accessTokenSecret: integrationAuthParameter("accessTokenSecret")
71
- }));
72
- function assertIntegrationAuthParams(config) {
73
- let result = safeParse(IntegrationAuthParamsSchema, config);
74
- if (!result.success) throw new CommerceSdkValidationError("Invalid IntegrationAuthProvider configuration", { issues: result.issues });
75
- }
76
- function getIntegrationAuthProvider(authParams) {
77
- let oauth = new OAuth1a({
78
- consumer: {
79
- key: authParams.consumerKey,
80
- secret: authParams.consumerSecret
81
- },
82
- signature_method: "HMAC-SHA256",
83
- hash_function: (baseString, key) => crypto.createHmac("sha256", key).update(baseString).digest("base64")
84
- }), oauthToken = {
85
- key: authParams.accessToken,
86
- secret: authParams.accessTokenSecret
87
- };
88
- return { getHeaders: (method, url$1) => {
89
- let urlString = url$1 instanceof URL ? url$1.toString() : url$1;
90
- return oauth.toHeader(oauth.authorize({
91
- url: urlString,
92
- method
93
- }, oauthToken));
94
- } };
95
- }
96
- export { IMS_AUTH_ENV, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
14
+ import{CommerceSdkValidationError}from"@adobe/aio-commerce-lib-core/error";import aioLibIms from"@adobe/aio-lib-ims";import{array,email,instance,minLength,nonEmpty,nonOptional,object,optional,parse,picklist,pipe,safeParse,string,transform,union,url}from"valibot";import crypto from"crypto";import OAuth1a from"oauth-1.0a";const imsAuthParameter=name=>pipe(string(`Expected a string value for the IMS auth parameter ${name}`),nonEmpty(`Expected a non-empty string value for the IMS auth parameter ${name}`)),stringArray=name=>pipe(array(string(),`Expected a string array value for the IMS auth parameter ${name}`)),ImsAuthEnvSchema=picklist([`prod`,`stage`]),ImsAuthParamsSchema=object({clientId:imsAuthParameter(`clientId`),clientSecrets:pipe(stringArray(`clientSecrets`),minLength(1,`Expected at least one client secret for IMS auth`)),technicalAccountId:imsAuthParameter(`technicalAccountId`),technicalAccountEmail:pipe(string(`Expected a string value for the IMS auth parameter technicalAccountEmail`),email(`Expected a valid email format for technicalAccountEmail`)),imsOrgId:imsAuthParameter(`imsOrgId`),environment:pipe(optional(ImsAuthEnvSchema)),context:pipe(optional(string())),scopes:pipe(stringArray(`scopes`),minLength(1,`Expected at least one scope for IMS auth`))}),{context,getToken}=aioLibIms;function toImsAuthConfig(config){return{scopes:config.scopes,env:config?.environment??`prod`,context:config.context??`aio-commerce-lib-auth-creds`,client_id:config.clientId,client_secrets:config.clientSecrets,technical_account_id:config.technicalAccountId,technical_account_email:config.technicalAccountEmail,ims_org_id:config.imsOrgId}}function assertImsAuthParams(config){let result=safeParse(ImsAuthParamsSchema,config);if(!result.success)throw new CommerceSdkValidationError(`Invalid ImsAuthProvider configuration`,{issues:result.issues})}function getImsAuthProvider(authParams){let getAccessToken=async()=>{let imsAuthConfig=toImsAuthConfig(authParams);return await context.set(imsAuthConfig.context,imsAuthConfig),getToken(imsAuthConfig.context,{})};return{getAccessToken,getHeaders:async()=>({Authorization:`Bearer ${await getAccessToken()}`,"x-api-key":authParams.clientId})}}const integrationAuthParameter=name=>pipe(string(`Expected a string value for the Commerce Integration parameter ${name}`),nonEmpty(`Expected a non-empty string value for the Commerce Integration parameter ${name}`)),UrlSchema=pipe(union([pipe(string(`Expected a string for the Adobe Commerce endpoint`),nonEmpty(`Expected a non-empty string for the Adobe Commerce endpoint`),url(`Expected a valid url for the Adobe Commerce endpoint`)),instance(URL)]),transform(url$1=>url$1 instanceof URL?url$1.toString():url$1)),IntegrationAuthParamsSchema=nonOptional(object({consumerKey:integrationAuthParameter(`consumerKey`),consumerSecret:integrationAuthParameter(`consumerSecret`),accessToken:integrationAuthParameter(`accessToken`),accessTokenSecret:integrationAuthParameter(`accessTokenSecret`)}));function assertIntegrationAuthParams(config){let result=safeParse(IntegrationAuthParamsSchema,config);if(!result.success)throw new CommerceSdkValidationError(`Invalid IntegrationAuthProvider configuration`,{issues:result.issues})}function getIntegrationAuthProvider(authParams){let oauth=new OAuth1a({consumer:{key:authParams.consumerKey,secret:authParams.consumerSecret},signature_method:`HMAC-SHA256`,hash_function:(baseString,key)=>crypto.createHmac(`sha256`,key).update(baseString).digest(`base64`)}),oauthToken={key:authParams.accessToken,secret:authParams.accessTokenSecret};return{getHeaders:(method,url$1)=>{let urlString=parse(UrlSchema,url$1);return oauth.toHeader(oauth.authorize({url:urlString,method},oauthToken))}}}export{assertImsAuthParams,assertIntegrationAuthParams,getImsAuthProvider,getIntegrationAuthProvider};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@adobe/aio-commerce-lib-auth",
3
3
  "type": "module",
4
4
  "author": "Adobe Inc.",
5
- "version": "0.3.4",
5
+ "version": "0.5.0",
6
6
  "private": false,
7
7
  "engines": {
8
8
  "node": ">=20 <=24"
@@ -54,10 +54,10 @@
54
54
  "@adobe/aio-commerce-lib-core": "0.4.1"
55
55
  },
56
56
  "devDependencies": {
57
- "@aio-commerce-sdk/config-typedoc": "1.0.0",
58
- "@aio-commerce-sdk/config-typescript": "1.0.0",
59
57
  "@aio-commerce-sdk/config-tsdown": "1.0.0",
60
- "@aio-commerce-sdk/config-vitest": "1.0.0"
58
+ "@aio-commerce-sdk/config-typedoc": "1.0.0",
59
+ "@aio-commerce-sdk/config-vitest": "1.0.0",
60
+ "@aio-commerce-sdk/config-typescript": "1.0.0"
61
61
  },
62
62
  "sideEffects": false,
63
63
  "scripts": {