Implementing Config with Effect: A Basic Example

Hello,

I read the Config documentation as well as some Discord threads in here.
Until now I was only having a "god-config-object" so I figured I would try to have a look at what is recommended for config with Effect.

As far as I understood, Config are not loaded the "Layer way". Instead we can use it by passing it as a parameter (as I saw here: https://github.com/effect-ts-app/libs/blob/e0a95874b3ef47e4e280dab43988890cdb51ee9c/packages/infra/_src/services/Store/index.ts#L16)

So I created something very basic to try:
export interface ShopifyClientMoneiConfig {
  shopName: string;
  accessToken: Redacted.Redacted;
}

export const ShopifyClientMoneiLive = (
  config: Config<ShopifyClientMoneiConfig>,
) =>
  Layer.effect(
    ShopifyClientMonei,
    config.pipe(
      Effect.map(({ shopName, accessToken }) => {
        return new Shopify({
          shopName,
          accessToken: Redacted.value(accessToken),
        });
      }),
    ),
  );


Is it the way it is supposed to be done, or have I gone the wrong way ?
Was this page helpful?