@adobe/aio-commerce-lib-auth 0.3.1 → 0.3.2
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 +8 -0
- package/dist/cjs/index.cjs +4 -4
- package/dist/cjs/index.d.cts +3 -3
- package/dist/es/index.d.ts +16 -16
- package/dist/es/index.js +4 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @adobe/aio-commerce-lib-auth
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`08edb37`](https://github.com/adobe/aio-commerce-sdk/commit/08edb372c6b1a97ffed26d5f84b1c189bd6bd330) Thanks [@jnatherley](https://github.com/jnatherley)! - `ImsAuthConfig.context` could be received as `undefined` by the `context.set` method, after an `assertImsAuthParams` due to us discarding the Valibot output (which was setting a default). Now, the value is manually defaulted if not set.
|
|
8
|
+
|
|
9
|
+
- [`0b37a82`](https://github.com/adobe/aio-commerce-sdk/commit/0b37a821f3a7d8c8acd1d2bb16e12b55a5ec7c71) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Fix small typo in validation message of `stringArray` schema.
|
|
10
|
+
|
|
3
11
|
## 0.3.1
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -21,7 +21,7 @@ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDes
|
|
|
21
21
|
value: mod,
|
|
22
22
|
enumerable: !0
|
|
23
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
|
|
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
25
|
PROD: "prod",
|
|
26
26
|
STAGE: "stage"
|
|
27
27
|
}, ImsAuthEnvSchema = (0, valibot.enum)(IMS_AUTH_ENV), ImsAuthParamsSchema = (0, valibot.object)({
|
|
@@ -31,14 +31,14 @@ const __adobe_aio_commerce_lib_core_error = __toESM(require("@adobe/aio-commerce
|
|
|
31
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
32
|
imsOrgId: imsAuthParameter("imsOrgId"),
|
|
33
33
|
environment: (0, valibot.pipe)((0, valibot.optional)(ImsAuthEnvSchema, IMS_AUTH_ENV.PROD)),
|
|
34
|
-
context: (0, valibot.pipe)((0, valibot.optional)((0, valibot.string)()
|
|
34
|
+
context: (0, valibot.pipe)((0, valibot.optional)((0, valibot.string)())),
|
|
35
35
|
scopes: (0, valibot.pipe)(stringArray("scopes"), (0, valibot.minLength)(1, "Expected at least one scope for IMS auth"))
|
|
36
36
|
});
|
|
37
37
|
function toImsAuthConfig(config) {
|
|
38
38
|
return {
|
|
39
39
|
scopes: config.scopes,
|
|
40
40
|
env: config?.environment ?? "prod",
|
|
41
|
-
context: config.context,
|
|
41
|
+
context: config.context ?? "aio-commerce-lib-auth-creds",
|
|
42
42
|
client_id: config.clientId,
|
|
43
43
|
client_secrets: config.clientSecrets,
|
|
44
44
|
technical_account_id: config.technicalAccountId,
|
|
@@ -53,7 +53,7 @@ function assertImsAuthParams(config) {
|
|
|
53
53
|
function getImsAuthProvider(authParams) {
|
|
54
54
|
let getAccessToken = async () => {
|
|
55
55
|
let imsAuthConfig = toImsAuthConfig(authParams);
|
|
56
|
-
return await __adobe_aio_lib_ims.context.set(
|
|
56
|
+
return await __adobe_aio_lib_ims.context.set(imsAuthConfig.context, imsAuthConfig), (0, __adobe_aio_lib_ims.getToken)(imsAuthConfig.context, {});
|
|
57
57
|
}, getHeaders = async () => {
|
|
58
58
|
let accessToken = await getAccessToken();
|
|
59
59
|
return {
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -29,7 +29,7 @@ declare const ImsAuthEnvSchema: valibot21.EnumSchema<{
|
|
|
29
29
|
/** Defines the schema to validate the necessary parameters for the IMS auth service. */
|
|
30
30
|
declare const ImsAuthParamsSchema: valibot21.ObjectSchema<{
|
|
31
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
|
|
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
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
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
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}`>]>;
|
|
@@ -37,8 +37,8 @@ declare const ImsAuthParamsSchema: valibot21.ObjectSchema<{
|
|
|
37
37
|
readonly PROD: "prod";
|
|
38
38
|
readonly STAGE: "stage";
|
|
39
39
|
}, undefined>, "prod">]>;
|
|
40
|
-
readonly context: valibot21.SchemaWithPipe<readonly [valibot21.OptionalSchema<valibot21.StringSchema<undefined>,
|
|
41
|
-
readonly scopes: valibot21.SchemaWithPipe<readonly [valibot21.SchemaWithPipe<readonly [valibot21.ArraySchema<valibot21.StringSchema<undefined>, `Expected a
|
|
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">]>;
|
|
42
42
|
}, undefined>;
|
|
43
43
|
/** Defines the parameters for the IMS auth service. */
|
|
44
44
|
type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import * as
|
|
15
|
+
import * as valibot0 from "valibot";
|
|
16
16
|
import { InferOutput } from "valibot";
|
|
17
17
|
|
|
18
18
|
//#region source/lib/ims-auth/schema.d.ts
|
|
@@ -22,23 +22,23 @@ declare const IMS_AUTH_ENV: {
|
|
|
22
22
|
readonly STAGE: "stage";
|
|
23
23
|
};
|
|
24
24
|
/** Validation schema for IMS auth environment values. */
|
|
25
|
-
declare const ImsAuthEnvSchema:
|
|
25
|
+
declare const ImsAuthEnvSchema: valibot0.EnumSchema<{
|
|
26
26
|
readonly PROD: "prod";
|
|
27
27
|
readonly STAGE: "stage";
|
|
28
28
|
}, undefined>;
|
|
29
29
|
/** Defines the schema to validate the necessary parameters for the IMS auth service. */
|
|
30
|
-
declare const ImsAuthParamsSchema:
|
|
31
|
-
readonly clientId:
|
|
32
|
-
readonly clientSecrets:
|
|
33
|
-
readonly technicalAccountId:
|
|
34
|
-
readonly technicalAccountEmail:
|
|
35
|
-
readonly imsOrgId:
|
|
36
|
-
readonly environment:
|
|
30
|
+
declare const ImsAuthParamsSchema: valibot0.ObjectSchema<{
|
|
31
|
+
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}`>]>;
|
|
32
|
+
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">]>;
|
|
33
|
+
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}`>]>;
|
|
34
|
+
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">]>;
|
|
35
|
+
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}`>]>;
|
|
36
|
+
readonly environment: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.EnumSchema<{
|
|
37
37
|
readonly PROD: "prod";
|
|
38
38
|
readonly STAGE: "stage";
|
|
39
39
|
}, undefined>, "prod">]>;
|
|
40
|
-
readonly context:
|
|
41
|
-
readonly scopes:
|
|
40
|
+
readonly context: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.StringSchema<undefined>, undefined>]>;
|
|
41
|
+
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
42
|
}, undefined>;
|
|
43
43
|
/** Defines the parameters for the IMS auth service. */
|
|
44
44
|
type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
|
|
@@ -147,11 +147,11 @@ type HttpMethodInput = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
|
147
147
|
* The schema for the Commerce Integration parameters.
|
|
148
148
|
* This is used to validate the parameters passed to the Commerce Integration provider.
|
|
149
149
|
*/
|
|
150
|
-
declare const IntegrationAuthParamsSchema:
|
|
151
|
-
readonly consumerKey:
|
|
152
|
-
readonly consumerSecret:
|
|
153
|
-
readonly accessToken:
|
|
154
|
-
readonly accessTokenSecret:
|
|
150
|
+
declare const IntegrationAuthParamsSchema: valibot0.NonOptionalSchema<valibot0.ObjectSchema<{
|
|
151
|
+
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}`>]>;
|
|
152
|
+
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}`>]>;
|
|
153
|
+
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}`>]>;
|
|
154
|
+
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
155
|
}, undefined>, undefined>;
|
|
156
156
|
/** Defines the parameters required for Commerce Integration authentication. */
|
|
157
157
|
type IntegrationAuthParams = InferOutput<typeof IntegrationAuthParamsSchema>;
|
package/dist/es/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { context, getToken } from "@adobe/aio-lib-ims";
|
|
|
16
16
|
import { array, email, enum as enum$1, instance, minLength, nonEmpty, nonOptional, object, optional, pipe, safeParse, string, transform, union, url } from "valibot";
|
|
17
17
|
import crypto from "crypto";
|
|
18
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
|
|
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
20
|
PROD: "prod",
|
|
21
21
|
STAGE: "stage"
|
|
22
22
|
}, ImsAuthEnvSchema = enum$1(IMS_AUTH_ENV), ImsAuthParamsSchema = object({
|
|
@@ -26,14 +26,14 @@ const imsAuthParameter = (name) => pipe(string(`Expected a string value for the
|
|
|
26
26
|
technicalAccountEmail: pipe(string("Expected a string value for the IMS auth parameter technicalAccountEmail"), email("Expected a valid email format for technicalAccountEmail")),
|
|
27
27
|
imsOrgId: imsAuthParameter("imsOrgId"),
|
|
28
28
|
environment: pipe(optional(ImsAuthEnvSchema, IMS_AUTH_ENV.PROD)),
|
|
29
|
-
context: pipe(optional(string()
|
|
29
|
+
context: pipe(optional(string())),
|
|
30
30
|
scopes: pipe(stringArray("scopes"), minLength(1, "Expected at least one scope for IMS auth"))
|
|
31
31
|
});
|
|
32
32
|
function toImsAuthConfig(config) {
|
|
33
33
|
return {
|
|
34
34
|
scopes: config.scopes,
|
|
35
35
|
env: config?.environment ?? "prod",
|
|
36
|
-
context: config.context,
|
|
36
|
+
context: config.context ?? "aio-commerce-lib-auth-creds",
|
|
37
37
|
client_id: config.clientId,
|
|
38
38
|
client_secrets: config.clientSecrets,
|
|
39
39
|
technical_account_id: config.technicalAccountId,
|
|
@@ -48,7 +48,7 @@ function assertImsAuthParams(config) {
|
|
|
48
48
|
function getImsAuthProvider(authParams) {
|
|
49
49
|
let getAccessToken = async () => {
|
|
50
50
|
let imsAuthConfig = toImsAuthConfig(authParams);
|
|
51
|
-
return await context.set(
|
|
51
|
+
return await context.set(imsAuthConfig.context, imsAuthConfig), getToken(imsAuthConfig.context, {});
|
|
52
52
|
}, getHeaders = async () => {
|
|
53
53
|
let accessToken = await getAccessToken();
|
|
54
54
|
return {
|