Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions packages/organization-config/src/getMfeConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,46 @@ 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,
params: {
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",
})
expect(config).toMatchObject({
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}`,
},
Expand All @@ -339,14 +364,17 @@ describe("getMfeConfig function", () => {
accessToken: ioAccessToken,
orderId: "order123",
skuId: "sku123",
identityType: "signup",
clientId: "client123",
scope: "scope123",
},
market: "market:id:ZKcv13rT",
})
expect(config).toMatchObject({
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}`,
},
Expand All @@ -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",
},
},
},
Expand All @@ -376,14 +405,17 @@ describe("getMfeConfig function", () => {
accessToken: ioAccessToken,
orderId: "order123",
skuListId: "skuList123",
identityType: "signup",
clientId: "client123",
scope: "scope123",
},
market: "market:id:ZKcv13rT",
})
expect(config).toMatchObject({
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}`,
},
Expand Down
46 changes: 45 additions & 1 deletion packages/organization-config/src/getMfeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ interface ConfigParams {
* Unique identifier for an SKU used to replace the `:sku_id` placeholder in URLs.
*/
skuId?: NullableType<string>
/**
* 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<string>
/**
* For the identity, it is the market used for the login process (e.g. a private market).
*/
scope?: NullableType<string>
/**
* 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<string>
/**
* Return URL after certain actions, which can be used to replace a `:return_url` placeholder in URLs.
*/
returnUrl?: NullableType<string>
/**
* URL to the reset password page, which can be used to replace a `:reset_password_url` placeholder in URLs.
*/
resetPasswordUrl?: NullableType<string>
}

interface GetMfeConfigProps {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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`
Expand Down
Loading