@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.
@@ -1,87 +0,0 @@
1
- /*
2
- * Copyright 2025 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {
14
- type InferOutput,
15
- nonEmpty,
16
- object,
17
- optional,
18
- parseJson,
19
- pipe,
20
- string,
21
- array as vArray,
22
- enum as vEnum,
23
- message as vMessage,
24
- } from "valibot";
25
-
26
- const imsAuthParameter = (name: string) =>
27
- pipe(
28
- string(`Expected a string value for the IMS auth parameter ${name}`),
29
- nonEmpty(
30
- `Expected a non-empty string value for the IMS auth parameter ${name}`,
31
- ),
32
- );
33
-
34
- const jsonStringArray = (name: string) => {
35
- const jsonStringArraySchema = vMessage(
36
- pipe(
37
- string(`Expected a string value for the IMS auth parameter ${name}`),
38
- nonEmpty(
39
- `Expected a non-empty string value for the IMS auth parameter ${name}`,
40
- ),
41
- parseJson(),
42
- ),
43
- `An error occurred while parsing the JSON string array parameter ${name}`,
44
- );
45
-
46
- return pipe(
47
- jsonStringArraySchema,
48
- vArray(
49
- string(),
50
- `Expected a stringified JSON array value for the IMS auth parameter ${name}`,
51
- ),
52
- );
53
- };
54
-
55
- /** The environments accepted by the IMS auth service. */
56
- export const IMS_AUTH_ENV = {
57
- PROD: "prod",
58
- STAGE: "stage",
59
- } as const;
60
-
61
- const ImsAuthEnvSchema = vEnum(IMS_AUTH_ENV);
62
-
63
- /** Defines the schema to validate the necessary parameters for the IMS auth service. */
64
- export const ImsAuthParamsSchema = object({
65
- AIO_COMMERCE_IMS_CLIENT_ID: imsAuthParameter("AIO_COMMERCE_IMS_CLIENT_ID"),
66
- AIO_COMMERCE_IMS_CLIENT_SECRETS: jsonStringArray(
67
- "AIO_COMMERCE_IMS_CLIENT_SECRETS",
68
- ),
69
- AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID: imsAuthParameter(
70
- "AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID",
71
- ),
72
-
73
- AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL: imsAuthParameter(
74
- "AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL",
75
- ),
76
- AIO_COMMERCE_IMS_IMS_ORG_ID: imsAuthParameter("AIO_COMMERCE_IMS_IMS_ORG_ID"),
77
-
78
- AIO_COMMERCE_IMS_ENV: pipe(optional(ImsAuthEnvSchema, IMS_AUTH_ENV.PROD)),
79
- AIO_COMMERCE_IMS_CTX: pipe(optional(string(), "aio-commerce-sdk-creds")),
80
- AIO_COMMERCE_IMS_SCOPES: jsonStringArray("AIO_COMMERCE_IMS_SCOPES"),
81
- });
82
-
83
- /** Defines the parameters for the IMS auth service. */
84
- export type ImsAuthParams = InferOutput<typeof ImsAuthParamsSchema>;
85
-
86
- /** Defines the environments accepted by the IMS auth service. */
87
- export type ImsAuthEnv = InferOutput<typeof ImsAuthEnvSchema>;
@@ -1,145 +0,0 @@
1
- /*
2
- * Copyright 2025 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import crypto from "node:crypto";
14
-
15
- import { err, ok, type Result } from "@adobe/aio-commerce-lib-core/result";
16
- import type { ValidationErrorType } from "@adobe/aio-commerce-lib-core/validation";
17
-
18
- import OAuth1a from "oauth-1.0a";
19
- import { type InferIssue, safeParse } from "valibot";
20
-
21
- import {
22
- type AdobeCommerceUri,
23
- type HttpMethodInput,
24
- type IntegrationAuthParams,
25
- IntegrationAuthParamsSchema,
26
- UrlSchema,
27
- } from "./schema";
28
-
29
- type IntegrationAuthHeader = "Authorization";
30
- type IntegrationAuthHeaders = Record<IntegrationAuthHeader, string>;
31
-
32
- /** Defines the configuration to create an {@link IntegrationAuthProvider}. */
33
- export interface IntegrationConfig {
34
- consumerKey: string;
35
- consumerSecret: string;
36
- accessToken: string;
37
- accessTokenSecret: string;
38
- }
39
-
40
- type ValidationIssues =
41
- | InferIssue<typeof IntegrationAuthParamsSchema>[]
42
- | InferIssue<typeof UrlSchema>[];
43
-
44
- /** Defines an error type for the integration auth service. */
45
- export type IntegrationAuthError = ValidationErrorType<
46
- "IntegrationAuthValidationError",
47
- ValidationIssues
48
- >;
49
-
50
- /** Defines an authentication provider for Adobe Commerce integrations. */
51
- export interface IntegrationAuthProvider {
52
- getHeaders: (
53
- method: HttpMethodInput,
54
- url: AdobeCommerceUri,
55
- ) => Result<IntegrationAuthHeaders, IntegrationAuthError>;
56
- }
57
-
58
- function makeIntegrationAuthValidationError(
59
- message: string,
60
- issues: ValidationIssues,
61
- ) {
62
- return {
63
- _tag: "IntegrationAuthValidationError",
64
- message,
65
- issues,
66
- } satisfies IntegrationAuthError;
67
- }
68
-
69
- function fromParams(params: IntegrationAuthParams) {
70
- return {
71
- consumerKey: params.AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY,
72
- consumerSecret: params.AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET,
73
- accessToken: params.AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN,
74
- accessTokenSecret: params.AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET,
75
- } satisfies IntegrationConfig;
76
- }
77
-
78
- /**
79
- * Creates an {@link IntegrationAuthProvider} based on the provided configuration.
80
- * @param config The configuration for the integration.
81
- * @returns An {@link IntegrationAuthProvider} instance that can be used to get auth headers.
82
- */
83
- export function getIntegrationAuthProvider(
84
- config: IntegrationConfig,
85
- ): IntegrationAuthProvider {
86
- const oauth = new OAuth1a({
87
- consumer: {
88
- key: config.consumerKey,
89
- secret: config.consumerSecret,
90
- },
91
- signature_method: "HMAC-SHA256",
92
- hash_function: (baseString, key) =>
93
- crypto.createHmac("sha256", key).update(baseString).digest("base64"),
94
- });
95
-
96
- const oauthToken = {
97
- key: config.accessToken,
98
- secret: config.accessTokenSecret,
99
- };
100
-
101
- const getHeaders = (method: HttpMethodInput, url: AdobeCommerceUri) => {
102
- const uriValidation = safeParse(UrlSchema, url);
103
- if (!uriValidation.success) {
104
- return err(
105
- makeIntegrationAuthValidationError(
106
- "Failed to validate the provided Adobe Commerce URL",
107
- uriValidation.issues,
108
- ),
109
- );
110
- }
111
-
112
- const finalUrl = uriValidation.output;
113
- const headers = oauth.toHeader(
114
- oauth.authorize({ url: finalUrl, method }, oauthToken),
115
- );
116
-
117
- return ok(headers);
118
- };
119
-
120
- return {
121
- getHeaders,
122
- };
123
- }
124
-
125
- /**
126
- * Tries to create an {@link IntegrationAuthProvider} based on the provided parameters.
127
- * @param params The parameters required for integration authentication.
128
- * @returns An {@link IntegrationAuthProvider} instance that can be used to get auth headers.
129
- */
130
- export function tryGetIntegrationAuthProvider(
131
- params: IntegrationAuthParams,
132
- ): Result<IntegrationAuthProvider, IntegrationAuthError> {
133
- const validation = safeParse(IntegrationAuthParamsSchema, params);
134
-
135
- if (!validation.success) {
136
- return err(
137
- makeIntegrationAuthValidationError(
138
- "Failed to validate the provided integration parameters",
139
- validation.issues,
140
- ),
141
- );
142
- }
143
-
144
- return ok(getIntegrationAuthProvider(fromParams(validation.output)));
145
- }
@@ -1,87 +0,0 @@
1
- /*
2
- * Copyright 2025 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {
14
- type InferInput,
15
- instance,
16
- nonEmpty,
17
- nonOptional,
18
- object,
19
- picklist,
20
- pipe,
21
- string,
22
- transform,
23
- union,
24
- url as vUrl,
25
- } from "valibot";
26
-
27
- /**
28
- * The HTTP methods supported by Commerce.
29
- * This is used to determine which headers to include in the signing of the authorization header.
30
- */
31
- const AllowedHttpMethod = ["GET", "POST", "PUT", "PATCH", "DELETE"] as const;
32
-
33
- export const HttpMethodSchema = picklist(AllowedHttpMethod);
34
- export type HttpMethodInput = InferInput<typeof HttpMethodSchema>;
35
-
36
- const integrationAuthParameter = (name: string) =>
37
- pipe(
38
- string(
39
- `Expected a string value for the Commerce Integration parameter ${name}`,
40
- ),
41
- nonEmpty(
42
- `Expected a non-empty string value for the Commerce Integration parameter ${name}`,
43
- ),
44
- );
45
-
46
- const BaseUrlSchema = pipe(
47
- string("Expected a string for the Adobe Commerce endpoint"),
48
- nonEmpty("Expected a non-empty string for the Adobe Commerce endpoint"),
49
- vUrl("Expected a valid url for the Adobe Commerce endpoint"),
50
- );
51
-
52
- export const UrlSchema = pipe(
53
- union([BaseUrlSchema, instance(URL)]),
54
- transform((url) => {
55
- if (url instanceof URL) {
56
- return url.toString();
57
- }
58
- return url;
59
- }),
60
- );
61
-
62
- export type AdobeCommerceUri = InferInput<typeof UrlSchema>;
63
-
64
- /**
65
- * The schema for the Commerce Integration parameters.
66
- * This is used to validate the parameters passed to the Commerce Integration provider.
67
- */
68
- export const IntegrationAuthParamsSchema = nonOptional(
69
- object({
70
- AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY: integrationAuthParameter(
71
- "AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY",
72
- ),
73
- AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET: integrationAuthParameter(
74
- "AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET",
75
- ),
76
- AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN: integrationAuthParameter(
77
- "AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN",
78
- ),
79
- AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET: integrationAuthParameter(
80
- "AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET",
81
- ),
82
- }),
83
- );
84
-
85
- export type IntegrationAuthParams = InferInput<
86
- typeof IntegrationAuthParamsSchema
87
- >;
@@ -1,147 +0,0 @@
1
- /*
2
- * Copyright 2025 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import { unwrap, unwrapErr } from "@adobe/aio-commerce-lib-core/result";
14
- import { getToken } from "@adobe/aio-lib-ims";
15
-
16
- import type { InferInput } from "valibot";
17
- import { describe, expect, test, vi } from "vitest";
18
-
19
- import {
20
- getImsAuthProvider,
21
- tryGetImsAuthProvider,
22
- } from "~/lib/ims-auth/provider";
23
-
24
- import { IMS_AUTH_ENV, type ImsAuthParamsSchema } from "~/lib/ims-auth/schema";
25
-
26
- vi.mock("@adobe/aio-lib-ims", async () => ({
27
- context: (await vi.importActual("@adobe/aio-lib-ims")).context,
28
- getToken: vi.fn(),
29
- }));
30
-
31
- describe("IMS Authentication", () => {
32
- describe("getImsAuthProvider", () => {
33
- test("should export token", async () => {
34
- const authToken = "supersecrettoken";
35
- vi.mocked(getToken).mockResolvedValue(authToken);
36
-
37
- const config = {
38
- clientId: "test-client-id",
39
- clientSecrets: ["supersecret"],
40
- technicalAccountId: "test-technical-account-id",
41
- technicalAccountEmail: "test-email@example.com",
42
- imsOrgId: "test-org-id",
43
- scopes: ["scope1", "scope2"],
44
- environment: IMS_AUTH_ENV.PROD,
45
- context: "test-context",
46
- };
47
-
48
- const imsAuthProvider = getImsAuthProvider(config);
49
- expect(imsAuthProvider).toBeDefined();
50
-
51
- const retrievedToken = await imsAuthProvider.getAccessToken();
52
- expect(unwrap(retrievedToken)).toEqual(authToken);
53
-
54
- const headers = unwrap(await imsAuthProvider.getHeaders());
55
- expect(headers).toHaveProperty("Authorization", `Bearer ${authToken}`);
56
- expect(headers).toHaveProperty("x-api-key", config.clientId);
57
- });
58
- });
59
-
60
- describe("tryGetImsAuthProvider", () => {
61
- const params = {
62
- AIO_COMMERCE_IMS_CLIENT_ID: "test-client-id",
63
- AIO_COMMERCE_IMS_CLIENT_SECRETS: JSON.stringify(["supersecret"]),
64
- AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID: "test-technical-account-id",
65
- AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL: "test-email@example.com",
66
- AIO_COMMERCE_IMS_IMS_ORG_ID: "test-org-id",
67
- AIO_COMMERCE_IMS_SCOPES: JSON.stringify(["scope1", "scope2"]),
68
- } satisfies InferInput<typeof ImsAuthParamsSchema>;
69
-
70
- test("should export token when all required params are provided", async () => {
71
- const authToken = "supersecrettoken";
72
- vi.mocked(getToken).mockResolvedValue(authToken);
73
-
74
- const imsAuthProvider = unwrap(tryGetImsAuthProvider(params));
75
- const retrievedToken = unwrap(await imsAuthProvider.getAccessToken());
76
- expect(retrievedToken).toEqual(authToken);
77
-
78
- const headers = unwrap(await imsAuthProvider.getHeaders());
79
- expect(headers).toHaveProperty("Authorization", `Bearer ${authToken}`);
80
- expect(headers).toHaveProperty(
81
- "x-api-key",
82
- params.AIO_COMMERCE_IMS_CLIENT_ID,
83
- );
84
- });
85
-
86
- test("should err with invalid params", () => {
87
- const result = unwrapErr(
88
- tryGetImsAuthProvider(
89
- {} as unknown as InferInput<typeof ImsAuthParamsSchema>,
90
- ),
91
- );
92
-
93
- expect(result).toHaveProperty("_tag", "ImsAuthValidationError");
94
- expect(result).toHaveProperty("issues", expect.any(Array));
95
- });
96
-
97
- test.each([
98
- "AIO_COMMERCE_IMS_CLIENT_ID",
99
- "AIO_COMMERCE_IMS_CLIENT_SECRETS",
100
- "AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_ID",
101
- "AIO_COMMERCE_IMS_TECHNICAL_ACCOUNT_EMAIL",
102
- "AIO_COMMERCE_IMS_IMS_ORG_ID",
103
- "AIO_COMMERCE_IMS_SCOPES",
104
- ])("should throw error when %s is missing", (param) => {
105
- const result = tryGetImsAuthProvider({
106
- ...params,
107
- [param]: undefined,
108
- } satisfies InferInput<typeof ImsAuthParamsSchema>);
109
-
110
- expect(() => unwrap(result)).toThrow();
111
-
112
- const error = unwrapErr(result);
113
- expect(error._tag).toEqual("ImsAuthValidationError");
114
- expect(error.message).toEqual(
115
- "Failed to validate the provided IMS parameters",
116
- );
117
-
118
- expect(error.issues).toHaveLength(1);
119
- expect(error.issues[0].message).toEqual(
120
- `Expected a string value for the IMS auth parameter ${param}`,
121
- );
122
- });
123
-
124
- test.each([
125
- ["[test, foo]", "AIO_COMMERCE_IMS_SCOPES"],
126
- ['[{test: "foo"}]', "AIO_COMMERCE_IMS_SCOPES"],
127
- ['["test"', "AIO_COMMERCE_IMS_SCOPES"],
128
- ["[test, foo]", "AIO_COMMERCE_IMS_CLIENT_SECRETS"],
129
- ['[{test: "foo"}]', "AIO_COMMERCE_IMS_CLIENT_SECRETS"],
130
- ['["test"', "AIO_COMMERCE_IMS_CLIENT_SECRETS"],
131
- ])(`should throw error when given %s as %s input"`, (param, key) => {
132
- const result = tryGetImsAuthProvider({
133
- ...params,
134
- [key]: param,
135
- } satisfies InferInput<typeof ImsAuthParamsSchema>);
136
-
137
- expect(() => unwrap(result)).toThrow();
138
-
139
- const error = unwrapErr(result);
140
- expect(error._tag).toEqual("ImsAuthValidationError");
141
- expect(error.issues).toHaveLength(1);
142
- expect(error.issues[0].message).toEqual(
143
- `An error occurred while parsing the JSON string array parameter ${key}`,
144
- );
145
- });
146
- });
147
- });
@@ -1,124 +0,0 @@
1
- /*
2
- * Copyright 2025 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import { unwrap, unwrapErr } from "@adobe/aio-commerce-lib-core/result";
14
- import type { InferInput } from "valibot";
15
-
16
- import { describe, expect, test } from "vitest";
17
- import {
18
- getIntegrationAuthProvider,
19
- tryGetIntegrationAuthProvider,
20
- } from "~/lib/integration-auth/provider";
21
-
22
- import type {
23
- IntegrationAuthParams,
24
- IntegrationAuthParamsSchema,
25
- } from "~/lib/integration-auth/schema";
26
-
27
- /** Regex to match the OAuth 1.0a header format. */
28
- const OAUTH1_REGEX =
29
- /^OAuth oauth_consumer_key="[^"]+", oauth_nonce="[^"]+", oauth_signature="[^"]+", oauth_signature_method="HMAC-SHA256", oauth_timestamp="[^"]+", oauth_token="[^"]+", oauth_version="1\.0"$/;
30
-
31
- describe("Commerce Integration Auth", () => {
32
- describe("getIntegrationAuthProvider", () => {
33
- test("should export getIntegrationAuthProvider", () => {
34
- const integrationAuthProvider = getIntegrationAuthProvider({
35
- consumerKey: "test-consumer-key",
36
- consumerSecret: "test-consumer-secret",
37
- accessToken: "test-access-token",
38
- accessTokenSecret: "test-access-token-secret",
39
- });
40
-
41
- const headers = unwrap(
42
- integrationAuthProvider.getHeaders("GET", "http://localhost/test"),
43
- );
44
-
45
- expect(headers).toHaveProperty(
46
- "Authorization",
47
- expect.stringMatching(OAUTH1_REGEX),
48
- );
49
- });
50
- });
51
-
52
- describe("tryGetIntegrationAuthProvider", () => {
53
- const params: IntegrationAuthParams = {
54
- AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY: "test-consumer-key",
55
- AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET: "test-consumer-secret",
56
- AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN: "test-access-token",
57
- AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET: "test-access-token-secret",
58
- };
59
-
60
- test("should export getIntegrationAccessToken", () => {
61
- const result = unwrap(tryGetIntegrationAuthProvider(params));
62
- const headers = unwrap(result.getHeaders("GET", "http://localhost/test"));
63
-
64
- expect(headers).toHaveProperty(
65
- "Authorization",
66
- expect.stringMatching(OAUTH1_REGEX),
67
- );
68
- });
69
-
70
- test("should err with invalid params", () => {
71
- const result = unwrapErr(
72
- tryGetIntegrationAuthProvider({} as unknown as IntegrationAuthParams),
73
- );
74
-
75
- expect(result).toHaveProperty("_tag", "IntegrationAuthValidationError");
76
- expect(result).toHaveProperty("issues", expect.any(Array));
77
- });
78
-
79
- test.each([
80
- "AIO_COMMERCE_INTEGRATIONS_CONSUMER_KEY",
81
- "AIO_COMMERCE_INTEGRATIONS_CONSUMER_SECRET",
82
- "AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN",
83
- "AIO_COMMERCE_INTEGRATIONS_ACCESS_TOKEN_SECRET",
84
- ])("should throw error when %s is missing", (param) => {
85
- const result = tryGetIntegrationAuthProvider({
86
- ...params,
87
- [param]: undefined,
88
- } satisfies InferInput<typeof IntegrationAuthParamsSchema>);
89
-
90
- expect(() => unwrap(result)).toThrow();
91
-
92
- const error = unwrapErr(result);
93
- expect(error._tag).toEqual("IntegrationAuthValidationError");
94
- expect(error.message).toEqual(
95
- "Failed to validate the provided integration parameters",
96
- );
97
-
98
- expect(error.issues).toHaveLength(1);
99
- expect(error.issues[0].message).toEqual(
100
- `Expected a string value for the Commerce Integration parameter ${param}`,
101
- );
102
- });
103
-
104
- test.each([
105
- ["localhost"],
106
- ["http:://"],
107
- ["https://"],
108
- ["//example.com"],
109
- ["http://user@:80"],
110
- ])("should throw an Error on invalid [%s] URL", (url) => {
111
- const integrationAuthProvider = unwrap(
112
- tryGetIntegrationAuthProvider(params),
113
- );
114
-
115
- const getHeadersResult = integrationAuthProvider.getHeaders("GET", url);
116
- const error = unwrapErr(getHeadersResult);
117
-
118
- expect(error._tag).toEqual("IntegrationAuthValidationError");
119
- expect(error.message).toEqual(
120
- "Failed to validate the provided Adobe Commerce URL",
121
- );
122
- });
123
- });
124
- });
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "extends": "@aio-commerce-sdk/config-typescript/tsconfig.base.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "rootDir": ".",
6
- "outDir": "./dist",
7
-
8
- "paths": {
9
- "~/*": ["./source/*"],
10
- "~~/*": ["./*"]
11
- }
12
- },
13
-
14
- "include": ["tsdown.config.ts", "source/**/*", "test/**/*"]
15
- }
package/tsdown.config.ts DELETED
@@ -1,7 +0,0 @@
1
- import { baseConfig } from "@aio-commerce-sdk/config-tsdown/tsdown.config.base";
2
- import { defineConfig } from "tsdown";
3
-
4
- export default defineConfig({
5
- ...baseConfig,
6
- entry: ["./source/index.ts"],
7
- });
package/vitest.config.ts DELETED
@@ -1,16 +0,0 @@
1
- import { resolve } from "node:path";
2
- import { defineConfig } from "vitest/config";
3
-
4
- export default defineConfig({
5
- resolve: {
6
- alias: {
7
- "~": resolve(__dirname, "./source"),
8
- "~~": resolve(__dirname, "./"),
9
- },
10
- },
11
-
12
- test: {
13
- globals: true,
14
- environment: "node",
15
- },
16
- });