@adobe/aio-commerce-lib-auth 0.2.0 → 0.3.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 +14 -0
- package/README.md +90 -79
- package/dist/cjs/index.cjs +186 -122
- package/dist/cjs/index.d.cts +34 -57
- package/dist/es/index.d.ts +30 -53
- package/dist/es/index.js +185 -121
- package/package.json +9 -3
- package/.turbo/turbo-build.log +0 -18
- package/source/index.ts +0 -35
- package/source/lib/ims-auth/provider.ts +0 -160
- package/source/lib/ims-auth/schema.ts +0 -87
- package/source/lib/integration-auth/provider.ts +0 -145
- package/source/lib/integration-auth/schema.ts +0 -87
- package/test/ims-auth.test.ts +0 -147
- package/test/integration-auth.test.ts +0 -124
- package/tsconfig.json +0 -15
- package/tsdown.config.ts +0 -7
- package/vitest.config.ts +0 -16
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,88 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import * as valibot25 from "valibot";
|
|
4
|
-
import { InferInput, InferIssue, InferOutput } from "valibot";
|
|
5
|
-
import * as url5 from "url";
|
|
1
|
+
import * as valibot24 from "valibot";
|
|
2
|
+
import { InferOutput } from "valibot";
|
|
6
3
|
|
|
7
4
|
//#region source/lib/ims-auth/schema.d.ts
|
|
8
5
|
declare const IMS_AUTH_ENV: {
|
|
9
6
|
readonly PROD: "prod";
|
|
10
7
|
readonly STAGE: "stage";
|
|
11
8
|
};
|
|
12
|
-
declare const ImsAuthEnvSchema:
|
|
9
|
+
declare const ImsAuthEnvSchema: valibot24.EnumSchema<{
|
|
13
10
|
readonly PROD: "prod";
|
|
14
11
|
readonly STAGE: "stage";
|
|
15
12
|
}, undefined>;
|
|
16
|
-
declare const ImsAuthParamsSchema:
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
13
|
+
declare const ImsAuthParamsSchema: valibot24.ObjectSchema<{
|
|
14
|
+
readonly clientId: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot24.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
|
|
15
|
+
readonly clientSecrets: valibot24.SchemaWithPipe<readonly [valibot24.SchemaWithPipe<readonly [valibot24.ArraySchema<valibot24.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot24.MinLengthAction<string[], 1, "Expected at least one client secret for IMS auth">]>;
|
|
16
|
+
readonly technicalAccountId: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot24.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
|
|
17
|
+
readonly technicalAccountEmail: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<"Expected a string value for the IMS auth parameter technicalAccountEmail">, valibot24.EmailAction<string, "Expected a valid email format for technicalAccountEmail">]>;
|
|
18
|
+
readonly imsOrgId: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<`Expected a string value for the IMS auth parameter ${string}`>, valibot24.NonEmptyAction<string, `Expected a non-empty string value for the IMS auth parameter ${string}`>]>;
|
|
19
|
+
readonly environment: valibot24.SchemaWithPipe<readonly [valibot24.OptionalSchema<valibot24.EnumSchema<{
|
|
23
20
|
readonly PROD: "prod";
|
|
24
21
|
readonly STAGE: "stage";
|
|
25
22
|
}, undefined>, "prod">]>;
|
|
26
|
-
readonly
|
|
27
|
-
readonly
|
|
23
|
+
readonly context: valibot24.SchemaWithPipe<readonly [valibot24.OptionalSchema<valibot24.StringSchema<undefined>, "aio-commerce-sdk-creds">]>;
|
|
24
|
+
readonly scopes: valibot24.SchemaWithPipe<readonly [valibot24.SchemaWithPipe<readonly [valibot24.ArraySchema<valibot24.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot24.MinLengthAction<string[], 1, "Expected at least one scope for IMS auth">]>;
|
|
28
25
|
}, undefined>;
|
|
29
26
|
type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
|
|
30
27
|
type ImsAuthEnv = InferOutput<typeof ImsAuthEnvSchema>;
|
|
31
28
|
//#endregion
|
|
32
29
|
//#region source/lib/ims-auth/provider.d.ts
|
|
33
|
-
type ImsAccessToken = string;
|
|
34
30
|
type ImsAuthHeader = "Authorization" | "x-api-key";
|
|
35
31
|
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
|
-
}
|
|
51
32
|
interface ImsAuthProvider {
|
|
52
|
-
getAccessToken: () => Promise<
|
|
53
|
-
getHeaders: () => Promise<
|
|
33
|
+
getAccessToken: () => Promise<string>;
|
|
34
|
+
getHeaders: () => Promise<ImsAuthHeaders>;
|
|
54
35
|
}
|
|
55
|
-
declare function
|
|
56
|
-
declare function
|
|
36
|
+
declare function assertImsAuthParams(config: Record<PropertyKey, unknown>): asserts config is ImsAuthParams;
|
|
37
|
+
declare function getImsAuthProvider(authParams: ImsAuthParams): {
|
|
38
|
+
getAccessToken: () => Promise<string>;
|
|
39
|
+
getHeaders: () => Promise<{
|
|
40
|
+
Authorization: string;
|
|
41
|
+
"x-api-key": string;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
57
44
|
//#endregion
|
|
58
45
|
//#region source/lib/integration-auth/schema.d.ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
readonly
|
|
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}`>]>;
|
|
46
|
+
type HttpMethodInput = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
47
|
+
declare const IntegrationAuthParamsSchema: valibot24.NonOptionalSchema<valibot24.ObjectSchema<{
|
|
48
|
+
readonly consumerKey: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot24.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
|
|
49
|
+
readonly consumerSecret: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot24.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
|
|
50
|
+
readonly accessToken: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot24.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
|
|
51
|
+
readonly accessTokenSecret: valibot24.SchemaWithPipe<readonly [valibot24.StringSchema<`Expected a string value for the Commerce Integration parameter ${string}`>, valibot24.NonEmptyAction<string, `Expected a non-empty string value for the Commerce Integration parameter ${string}`>]>;
|
|
68
52
|
}, undefined>, undefined>;
|
|
69
|
-
type IntegrationAuthParams =
|
|
53
|
+
type IntegrationAuthParams = InferOutput<typeof IntegrationAuthParamsSchema>;
|
|
70
54
|
//#endregion
|
|
71
55
|
//#region source/lib/integration-auth/provider.d.ts
|
|
72
56
|
type IntegrationAuthHeader = "Authorization";
|
|
73
57
|
type IntegrationAuthHeaders = Record<IntegrationAuthHeader, string>;
|
|
74
|
-
|
|
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>;
|
|
58
|
+
type AdobeCommerceUrl = string | URL;
|
|
82
59
|
interface IntegrationAuthProvider {
|
|
83
|
-
getHeaders: (method: HttpMethodInput, url:
|
|
60
|
+
getHeaders: (method: HttpMethodInput, url: AdobeCommerceUrl) => IntegrationAuthHeaders;
|
|
84
61
|
}
|
|
85
|
-
declare function
|
|
86
|
-
declare function
|
|
62
|
+
declare function assertIntegrationAuthParams(config: Record<PropertyKey, unknown>): asserts config is IntegrationAuthParams;
|
|
63
|
+
declare function getIntegrationAuthProvider(authParams: IntegrationAuthParams): IntegrationAuthProvider;
|
|
87
64
|
//#endregion
|
|
88
|
-
export { IMS_AUTH_ENV,
|
|
65
|
+
export { IMS_AUTH_ENV, ImsAuthEnv, ImsAuthParams, ImsAuthProvider, IntegrationAuthParams, IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
|
package/dist/es/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ErrorType, Result } from "@adobe/aio-commerce-lib-core/result";
|
|
2
1
|
import * as valibot0 from "valibot";
|
|
3
|
-
import {
|
|
4
|
-
import { ValidationErrorType } from "@adobe/aio-commerce-lib-core/validation";
|
|
5
|
-
import * as url39 from "url";
|
|
2
|
+
import { InferOutput } from "valibot";
|
|
6
3
|
|
|
7
4
|
//#region source/lib/ims-auth/schema.d.ts
|
|
8
5
|
declare const IMS_AUTH_ENV: {
|
|
@@ -14,75 +11,55 @@ declare const ImsAuthEnvSchema: valibot0.EnumSchema<{
|
|
|
14
11
|
readonly STAGE: "stage";
|
|
15
12
|
}, undefined>;
|
|
16
13
|
declare const ImsAuthParamsSchema: valibot0.ObjectSchema<{
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
14
|
+
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}`>]>;
|
|
15
|
+
readonly clientSecrets: valibot0.SchemaWithPipe<readonly [valibot0.SchemaWithPipe<readonly [valibot0.ArraySchema<valibot0.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot0.MinLengthAction<string[], 1, "Expected at least one client secret for IMS auth">]>;
|
|
16
|
+
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}`>]>;
|
|
17
|
+
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">]>;
|
|
18
|
+
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}`>]>;
|
|
19
|
+
readonly environment: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.EnumSchema<{
|
|
23
20
|
readonly PROD: "prod";
|
|
24
21
|
readonly STAGE: "stage";
|
|
25
22
|
}, undefined>, "prod">]>;
|
|
26
|
-
readonly
|
|
27
|
-
readonly
|
|
23
|
+
readonly context: valibot0.SchemaWithPipe<readonly [valibot0.OptionalSchema<valibot0.StringSchema<undefined>, "aio-commerce-sdk-creds">]>;
|
|
24
|
+
readonly scopes: valibot0.SchemaWithPipe<readonly [valibot0.SchemaWithPipe<readonly [valibot0.ArraySchema<valibot0.StringSchema<undefined>, `Expected a stringified JSON array value for the IMS auth parameter ${string}`>]>, valibot0.MinLengthAction<string[], 1, "Expected at least one scope for IMS auth">]>;
|
|
28
25
|
}, undefined>;
|
|
29
26
|
type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
|
|
30
27
|
type ImsAuthEnv = InferOutput<typeof ImsAuthEnvSchema>;
|
|
31
28
|
//#endregion
|
|
32
29
|
//#region source/lib/ims-auth/provider.d.ts
|
|
33
|
-
type ImsAccessToken = string;
|
|
34
30
|
type ImsAuthHeader = "Authorization" | "x-api-key";
|
|
35
31
|
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
|
-
}
|
|
51
32
|
interface ImsAuthProvider {
|
|
52
|
-
getAccessToken: () => Promise<
|
|
53
|
-
getHeaders: () => Promise<
|
|
33
|
+
getAccessToken: () => Promise<string>;
|
|
34
|
+
getHeaders: () => Promise<ImsAuthHeaders>;
|
|
54
35
|
}
|
|
55
|
-
declare function
|
|
56
|
-
declare function
|
|
36
|
+
declare function assertImsAuthParams(config: Record<PropertyKey, unknown>): asserts config is ImsAuthParams;
|
|
37
|
+
declare function getImsAuthProvider(authParams: ImsAuthParams): {
|
|
38
|
+
getAccessToken: () => Promise<string>;
|
|
39
|
+
getHeaders: () => Promise<{
|
|
40
|
+
Authorization: string;
|
|
41
|
+
"x-api-key": string;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
57
44
|
//#endregion
|
|
58
45
|
//#region source/lib/integration-auth/schema.d.ts
|
|
59
|
-
|
|
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>;
|
|
46
|
+
type HttpMethodInput = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
63
47
|
declare const IntegrationAuthParamsSchema: valibot0.NonOptionalSchema<valibot0.ObjectSchema<{
|
|
64
|
-
readonly
|
|
65
|
-
readonly
|
|
66
|
-
readonly
|
|
67
|
-
readonly
|
|
48
|
+
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}`>]>;
|
|
49
|
+
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}`>]>;
|
|
50
|
+
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}`>]>;
|
|
51
|
+
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}`>]>;
|
|
68
52
|
}, undefined>, undefined>;
|
|
69
|
-
type IntegrationAuthParams =
|
|
53
|
+
type IntegrationAuthParams = InferOutput<typeof IntegrationAuthParamsSchema>;
|
|
70
54
|
//#endregion
|
|
71
55
|
//#region source/lib/integration-auth/provider.d.ts
|
|
72
56
|
type IntegrationAuthHeader = "Authorization";
|
|
73
57
|
type IntegrationAuthHeaders = Record<IntegrationAuthHeader, string>;
|
|
74
|
-
|
|
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>;
|
|
58
|
+
type AdobeCommerceUrl = string | URL;
|
|
82
59
|
interface IntegrationAuthProvider {
|
|
83
|
-
getHeaders: (method: HttpMethodInput, url:
|
|
60
|
+
getHeaders: (method: HttpMethodInput, url: AdobeCommerceUrl) => IntegrationAuthHeaders;
|
|
84
61
|
}
|
|
85
|
-
declare function
|
|
86
|
-
declare function
|
|
62
|
+
declare function assertIntegrationAuthParams(config: Record<PropertyKey, unknown>): asserts config is IntegrationAuthParams;
|
|
63
|
+
declare function getIntegrationAuthProvider(authParams: IntegrationAuthParams): IntegrationAuthProvider;
|
|
87
64
|
//#endregion
|
|
88
|
-
export { IMS_AUTH_ENV,
|
|
65
|
+
export { IMS_AUTH_ENV, ImsAuthEnv, ImsAuthParams, ImsAuthProvider, IntegrationAuthParams, IntegrationAuthProvider, assertImsAuthParams, assertIntegrationAuthParams, getImsAuthProvider, getIntegrationAuthProvider };
|