@axa-fr/slimfaas-planet-saver

中文文档
0.88.0发布于 2026/11/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2563

Pure vanilla javascript which call SlimFaas API to convert infrastructures resilience to an UX resilience and help to save the planet

原始使用文档
文档目录6 节
  1. Getting Started
  2. Usage:
  3. Run the demo
  4. Configuration Options
  5. Notes on Behavior
  6. Lifecycle

@axa-fr/slimfaas-planet-saver

npm version

SlimFaas

A Vanilla JS project to save the planet. SlimFaas (https://github.com/SlimPlanet/slimfaas) is the slimmest and simplest Function As A Service on Kubernetes. It works as a proxy that you can be deployed in your namespace.

SlimFaas API can give to the frontend information about the infrastructure state. It is a mind changer !

Why?

Because in production instead of setting up 2 replicas of your API backend, you can set up 0 replicas and use an UX that will show the user that the backend is down instead ! @axa-fr/slimfaas-planet-saver is here to for doing that easy.

SlimFaas Planet Saver

Getting Started

npm install @axa-fr/slimfaas-planet-saver

Example usage with react :

import React, { useState, useEffect, useRef } from 'react';
import { SlimFaasPlanetSaver } from '@axa-fr/slimfaas-planet-saver';

const PlanetSaver = ({ children, baseUrl, fetch, noActivityTimeout=60000, behavior={} }) => {
    const [isFirstStart, setIsFirstStart] = useState(true);
    const instanceRef = useRef(null);

    useEffect(() => {
        if (!baseUrl) return;

        if (instanceRef.current) return;

        const instance = new SlimFaasPlanetSaver(baseUrl, {
            interval: 2000,
            fetch,
            behavior,
            updateCallback: (data) => {
                const inst = instanceRef.current;
                // Filter only the items that block the UI (WakeUp+BlockUI)
                const blockingItems = data.filter(
                    (item) => inst?.getBehavior(item.Name) === 'WakeUp+BlockUI'
                );

                // If all blocking items are ready, set isFirstStart to false
                const allBlockingReady = blockingItems.every(
                    (item) => item.NumberReady >= 1
                );
                if (allBlockingReady && isFirstStart) {
                    setIsFirstStart(false);
                }
            },
            errorCallback: (error) => {
                console.error('Error detected :', error);
            },
            overlayStartingMessage: '🌳 Starting the environment.... 🌳',
            overlayNoActivityMessage: 'Waiting activity to start environment...',
            overlayErrorMessage: 'An error occurred when starting environment. Please contact an administrator.',
            overlaySecondaryMessage: 'Startup should be fast, but if no machines are available it can take several minutes.',
            overlayLoadingIcon: '🌍',
            overlayErrorSecondaryMessage: 'If the error persists, please contact an administrator.',
            noActivityTimeout
        });

        instanceRef.current = instance;

        // Initialiser les effets de bord
        instance.initialize();
        instance.startPolling();

        return () => {
            try {
                instance.cleanup();
            } finally {
                instanceRef.current = null;
            }
        };
    }, [baseUrl]);

    if (isFirstStart) {
        return null;
    }

    return <>{children}</>;
};

export default PlanetSaver;



Usage:

const behavior: {
    "api-speech-to-text": "WakeUp",
    "heavy-pdf-service": "WakeUp+BlockUI",
    "deprecated-service": "None"
}

<PlanetSaver baseUrl="http://slimfaas.mycompany.com" fetch={window.fetch} behavior={behavior}>
  <App />
</PlanetSaver>

Run the demo

git clone https://github.com/SlimPlanet/slimfaas.git
cd slimfaas/src/SlimFaasPlanetSaver
npm i
npm run dev

This will launch a local dev server, letting you see SlimFaasPlanetSaver in action.


Configuration Options

When you create a new SlimFaasPlanetSaver(baseUrl, options), you can provide the following optional properties in the options object:

PropertyTypeDefaultDescription
updateCallback(data: any[]) => void() => {}Function called after a successful fetch of the functions’ status. The array data includes objects with info about each function, for example: [{ Name: 'myFunc', NumberReady: 1 }, ...].
errorCallback(errorMessage: string) => void() => {}Function called if an error occurs during the status fetch (e.g., network error). Receives an errorMessage string.
intervalnumber5000How frequently (in ms) the polling should run.
overlayStartingMessagestring"🌳 Starting the environment.... 🌳"Main message shown on the overlay when the environment is waking up.
overlayNoActivityMessagestring"Waiting activity to start environment..."Message shown if there is no user activity (mouse movement) for too long, but the environment is not ready yet.
overlayErrorMessagestring"An error occurred while starting the environment."Main message shown on the overlay if an error occurs (e.g., network error).
overlaySecondaryMessagestring"Startup should be fast, but if no machines are available it can take several minutes."Secondary message shown on the overlay when the environment is waking up.
overlayErrorSecondaryMessagestring"If the error persists, please contact an administrator."Secondary message shown on the overlay when an error occurs.
overlayLoadingIconstring"🌍"Text or icon shown on the overlay. By default, it is animated to spin.
noActivityTimeoutnumber60000How long (in ms) to wait for mouse movement before concluding there is no activity. If no activity is detected, a different overlay message is displayed.
wakeUpTimeoutnumber60000If a function was recently “woken up,” we’ll skip re-calling wake-up for that function within this timeout window (in ms).
fetchtypeof fetchGlobal fetchCustom fetch function if you want to provide your own (e.g., for SSR, or if your environment doesn't have a global fetch).
behavior{ [functionName: string]: 'WakeUp+BlockUI' | 'WakeUp' | 'None' }Not set; defaults each function to "WakeUp+BlockUI" if unspecifiedAllows you to override how each function is handled: 1. "WakeUp+BlockUI": wakes the function and blocks the UI with the overlay until it’s ready. 2. "WakeUp": wakes without blocking the UI. 3. "None": no wake-up call.

Notes on Behavior

If a function is not specified in the behavior map, it defaults to "WakeUp+BlockUI".

  • "WakeUp+BlockUI" means the overlay will be shown until that function is NumberReady >= 1.
  • "WakeUp" means we attempt to wake up the function, but do not keep the overlay shown specifically for that function.
  • "None" means the function will neither be woken up nor block the UI.

Lifecycle

  1. Initialize Call instance.initialize() to create the overlay elements, inject styles, and bind event listeners (e.g., for mouse movement).

  2. Start Polling Call instance.startPolling() to begin the periodic checks of the environment. If the environment is not ready, the overlay will appear.

  3. Stop Polling / Cleanup When your component unmounts or you no longer need to monitor the environment, call instance.cleanup(). This removes the overlay, styles, and any timers or event listeners.

版本与发布记录

@axa-fr/slimfaas-planet-saver 共发布 867 个版本,首次发布于 2024/11/30;过去 12 个月发布了 275 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.88.0latest2026/11/07今天
0.87.12026/11/07今天
0.87.02026/11/053 天前
0.87.0-dev.1209dev2026/11/043 天前
0.86.42026/11/025 天前
0.86.32026/11/025 天前

关于 @axa-fr/slimfaas-planet-saver 的常见问题

@axa-fr/slimfaas-planet-saver 是什么?

Pure vanilla javascript which call SlimFaas API to convert infrastructures resilience to an UX resilience and help to save the planet

如何安装 @axa-fr/slimfaas-planet-saver?

在项目目录运行 npm install @axa-fr/slimfaas-planet-saver,或使用 pnpm add / yarn add / bun add。

@axa-fr/slimfaas-planet-saver 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@axa-fr/slimfaas-planet-saver 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@axa-fr/slimfaas-planet-saver 可以商用吗?

@axa-fr/slimfaas-planet-saver 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@axa-fr/slimfaas-planet-saver 的下载量有多少?

根据 npm 官方下载统计,@axa-fr/slimfaas-planet-saver 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,563 次,日均约 85 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@axa-fr/slimfaas-planet-saver 还在维护吗?

最新版本 0.88.0 发布于 2026/11/07(今天);至今共发布 867 个版本,其中过去 12 个月发布了 275 个;首次发布于 2024/11/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。