diff --git a/packages/organization-config/src/getMfeConfig.test.ts b/packages/organization-config/src/getMfeConfig.test.ts index 09ecc94..fd43905 100644 --- a/packages/organization-config/src/getMfeConfig.test.ts +++ b/packages/organization-config/src/getMfeConfig.test.ts @@ -311,6 +311,25 @@ describe("getMfeConfig function", () => { expect(config?.language).toBe("it-IT") }) + it("should use default links even when params are not set", () => { + const config = getMfeConfig({ + jsonConfig: null, + params: { + accessToken: ioAccessToken, + }, + market: "market:id:ZKcv13rT", + }) + expect(config).toMatchObject({ + links: { + cart: `https://demo-store.commercelayer.app/cart/:order_id?accessToken=${ioAccessToken}`, + checkout: `https://demo-store.commercelayer.app/checkout/:order_id?accessToken=${ioAccessToken}`, + identity: `https://demo-store.commercelayer.app/identity/:identity_type?clientId=:client_id&scope=:scope`, + microstore: `https://demo-store.commercelayer.app/microstore/sku/:sku_id?accessToken=${ioAccessToken}`, + my_account: `https://demo-store.commercelayer.app/my-account?accessToken=${ioAccessToken}`, + }, + }) + }) + it("should use default links set to our official build-in apps (microstore as list)", () => { const config = getMfeConfig({ jsonConfig: null, @@ -318,6 +337,12 @@ describe("getMfeConfig function", () => { accessToken: ioAccessToken, orderId: "order123", skuListId: "skuList123", + identityType: "login", + clientId: "client123", + scope: "scope123", + publicScope: "public_scope123", + returnUrl: "https://example.com/return", + resetPasswordUrl: "https://example.com/reset-password", }, market: "market:id:ZKcv13rT", }) @@ -325,7 +350,7 @@ describe("getMfeConfig function", () => { links: { cart: `https://demo-store.commercelayer.app/cart/order123?accessToken=${ioAccessToken}`, checkout: `https://demo-store.commercelayer.app/checkout/order123?accessToken=${ioAccessToken}`, - identity: `https://demo-store.commercelayer.app/identity`, + identity: `https://demo-store.commercelayer.app/identity/login?clientId=client123&scope=scope123&publicScope=public_scope123&returnUrl=https://example.com/return&resetPasswordUrl=https://example.com/reset-password`, microstore: `https://demo-store.commercelayer.app/microstore/list/skuList123?accessToken=${ioAccessToken}`, my_account: `https://demo-store.commercelayer.app/my-account?accessToken=${ioAccessToken}`, }, @@ -339,6 +364,9 @@ describe("getMfeConfig function", () => { accessToken: ioAccessToken, orderId: "order123", skuId: "sku123", + identityType: "signup", + clientId: "client123", + scope: "scope123", }, market: "market:id:ZKcv13rT", }) @@ -346,7 +374,7 @@ describe("getMfeConfig function", () => { links: { cart: `https://demo-store.commercelayer.app/cart/order123?accessToken=${ioAccessToken}`, checkout: `https://demo-store.commercelayer.app/checkout/order123?accessToken=${ioAccessToken}`, - identity: `https://demo-store.commercelayer.app/identity`, + identity: `https://demo-store.commercelayer.app/identity/signup?clientId=client123&scope=scope123`, microstore: `https://demo-store.commercelayer.app/microstore/sku/sku123?accessToken=${ioAccessToken}`, my_account: `https://demo-store.commercelayer.app/my-account?accessToken=${ioAccessToken}`, }, @@ -367,7 +395,8 @@ describe("getMfeConfig function", () => { "market:id:ZKcv13rT": { links: { cart: "https://market-cart.example.com/:order_id?accessToken=:access_token", - identity: "https://custom-identity.example.com", + identity: + "https://custom-identity.example.com/:identity_type?scope=:scope&clientId=:client_id", }, }, }, @@ -376,6 +405,9 @@ describe("getMfeConfig function", () => { accessToken: ioAccessToken, orderId: "order123", skuListId: "skuList123", + identityType: "signup", + clientId: "client123", + scope: "scope123", }, market: "market:id:ZKcv13rT", }) @@ -383,7 +415,7 @@ describe("getMfeConfig function", () => { links: { cart: `https://market-cart.example.com/order123?accessToken=${ioAccessToken}`, checkout: `https://custom-checkout.example.com/order123?accessToken=${ioAccessToken}`, - identity: `https://custom-identity.example.com`, + identity: `https://custom-identity.example.com/signup?scope=scope123&clientId=client123`, microstore: `https://demo-store.commercelayer.app/microstore/list/skuList123?accessToken=${ioAccessToken}`, my_account: `https://demo-store.commercelayer.app/my-account?accessToken=${ioAccessToken}`, }, diff --git a/packages/organization-config/src/getMfeConfig.ts b/packages/organization-config/src/getMfeConfig.ts index d40621a..dea3d9e 100644 --- a/packages/organization-config/src/getMfeConfig.ts +++ b/packages/organization-config/src/getMfeConfig.ts @@ -41,6 +41,30 @@ interface ConfigParams { * Unique identifier for an SKU used to replace the `:sku_id` placeholder in URLs. */ skuId?: NullableType + /** + * Type used for the identity, which can be used to replace a `:identity_type` placeholder in URLs. + */ + identityType?: NullableType<"login" | "signup"> + /** + * Client ID used for authentication, which can be used to replace a `:client_id` placeholder in URLs. + */ + clientId?: NullableType + /** + * For the identity, it is the market used for the login process (e.g. a private market). + */ + scope?: NullableType + /** + * For the identity, it is the default scope used by the app to obtain the organization settings needed to customize the UI (name, logo, colors, etc.). + */ + publicScope?: NullableType + /** + * Return URL after certain actions, which can be used to replace a `:return_url` placeholder in URLs. + */ + returnUrl?: NullableType + /** + * URL to the reset password page, which can be used to replace a `:reset_password_url` placeholder in URLs. + */ + resetPasswordUrl?: NullableType } interface GetMfeConfigProps { @@ -97,6 +121,15 @@ export function getMfeConfig({ .replace(/:order_id/g, params?.orderId ?? ":order_id") .replace(/:sku_list_id/g, params?.skuListId ?? ":sku_list_id") .replace(/:sku_id/g, params?.skuId ?? ":sku_id") + .replace(/:identity_type/g, params?.identityType ?? ":identity_type") + .replace(/:client_id/g, params?.clientId ?? ":client_id") + .replace(/:scope/g, params?.scope ?? ":scope") + .replace(/:public_scope/g, params?.publicScope ?? ":public_scope") + .replace(/:return_url/g, params?.returnUrl ?? ":return_url") + .replace( + /:reset_password_url/g, + params?.resetPasswordUrl ?? ":reset_password_url", + ) return JSON.parse(replacedConfig) } @@ -142,7 +175,18 @@ function getDefaults({ params }: GetMfeConfigProps): DefaultMfeConfig { cart: `${appEndpoint}/cart/:order_id?accessToken=:access_token`, checkout: `${appEndpoint}/checkout/:order_id?accessToken=:access_token`, my_account: `${appEndpoint}/my-account?accessToken=:access_token`, - identity: `${appEndpoint}/identity`, + identity: `${appEndpoint}/identity/:identity_type?${[ + "clientId=:client_id", + "scope=:scope", + params.publicScope != null ? "publicScope=:public_scope" : null, + params.lang != null ? "lang=:lang" : null, + params.returnUrl != null ? "returnUrl=:return_url" : null, + params.resetPasswordUrl != null + ? "resetPasswordUrl=:reset_password_url" + : null, + ] + .filter((part) => part != null) + .join("&")}`, microstore: params.skuListId != null ? `${appEndpoint}/microstore/list/:sku_list_id?accessToken=:access_token`