saltra-integration by davidcastagnetoa/skills
npx skills add https://github.com/davidcastagnetoa/skills --skill saltra-integration集成与 SALTRA v4 API(西班牙社会保障系统)的新操作。
import axios from "axios";
import config from "../config/config.js";
import logger from "../utils/logger.js";
let saltraToken = null;
let tokenExpiry = 0;
const getSaltraToken = async () => {
if (saltraToken && Date.now() < tokenExpiry) return saltraToken;
const response = await axios.post(`${config.SALTRA_API_URL}/auth/login`, {
email: config.SALTRA_EMAIL,
password: config.SALTRA_PASSWORD,
});
saltraToken = response.data.access_token;
tokenExpiry = Date.now() + (response.data.expires_in - 300) * 1000; // 5分钟安全边际
return saltraToken;
};
export const nuevaOperacionSaltra = async (datos, certSecret) => {
const token = await getSaltraToken();
const response = await axios.post(
`${config.SALTRA_API_URL}/seg-social/operacion`,
{
...datos,
test: config.NODE_ENV !== "production" ? 1 : 0,
},
{
headers: {
Authorization: `Bearer ${token}`,
"X-Cert-Secret": certSecret,
"Content-Type": "application/json",
},
}
);
logger.debug({ request: datos, response: response.data }, "SALTRA operacion");
return response.data;
};
Integra nuevas operaciones con la API SALTRA v4 (Seguridad Social espanola).
import axios from "axios";
import config from "../config/config.js";
import logger from "../utils/logger.js";
let saltraToken = null;
let tokenExpiry = 0;
const getSaltraToken = async () => {
if (saltraToken && Date.now() < tokenExpiry) return saltraToken;
const response = await axios.post(`${config.SALTRA_API_URL}/auth/login`, {
email: config.SALTRA_EMAIL,
password: config.SALTRA_PASSWORD,
});
saltraToken = response.data.access_token;
tokenExpiry = Date.now() + (response.data.expires_in - 300) * 1000; // 5min safety margin
return saltraToken;
};
export const nuevaOperacionSaltra = async (datos, certSecret) => {
const token = await getSaltraToken();
const response = await axios.post(
`${config.SALTRA_API_URL}/seg-social/operacion`,
{
...datos,
test: config.NODE_ENV !== "production" ? 1 : 0,
},
{
headers: {
Authorization: `Bearer ${token}`,
"X-Cert-Secret": certSecret,
"Content-Type": "application/json",
},
}
);
logger.debug({ request: datos, response: response.data }, "SALTRA operacion");
return response.data;
};
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 方法 | 路径 | 描述 | 状态 |
|---|---|---|---|
| POST | /auth/login | 获取访问令牌 | 已实现 |
| POST | /seg-social/alta | 登记员工入职 | 已实现 |
| POST | /seg-social/baja | 登记员工离职 | 已实现 |
| GET | /seg-social/nss-by-ipf | 通过 DNI + 姓氏查询 NSS | 已实现 |
| POST | /certificate | 上传 p12/pfx 数字证书 | 已实现 |
{
"naf": "123456789012", // NSS (12位数字)
"ipf": "12345678A", // DNI/NIE
"nombre": "Juan",
"apellido1": "Garcia",
"apellido2": "Lopez",
"fecha_nacimiento": "1990-01-15",
"sexo": "H", // H = 男性, M = 女性
"regimen": "0111", // 通用制度
"ccc": "28123456789", // 公司 CCC (11位数字)
"grupo_cotizacion": "07",
"fecha_alta": "2024-01-15",
"cno": "5120", // 国家职业代码
"tipo_contrato": "100",
"coeficiente_jornada": "1000", // 1000 = 全职
"cert_secret": "xxx", // 来自公司数字证书
"test": 1 // 1 = 测试模式, 0 = 生产模式
}
{
"naf": "123456789012", // NSS
"ipf": "12345678A", // DNI/NIE
"fecha_baja": "2024-06-30",
"causa_baja": "51", // 原因代码 (51 = 自愿离职)
"ccc": "28123456789",
"cert_secret": "xxx",
"test": 1
}
try {
const result = await darAlta(datos, certSecret);
return result;
} catch (error) {
if (error.response?.data?.message) {
// SALTRA 可读错误
logger.error({ saltraError: error.response.data }, "Error SALTRA");
throw new Error(`Error SALTRA: ${error.response.data.message}`);
}
throw error;
}
| 概念 | 约定 |
|---|---|
| 令牌缓存 | 始终在过期前5分钟复用 |
| 测试模式 | 在非生产环境中强制设置 test=1 |
| cert_secret | 从 Company.saltra_cert_secret 获取,上传证书时存储 |
| 错误 | 解析 response.data.message 以获取用户可读的错误信息 |
| 日志记录 | 在 debug 级别记录完整的请求和响应 |
| 配置 | config.js 中的变量:SALTRA_API_URL, SALTRA_EMAIL, SALTRA_PASSWORD |
test: 1)每周安装数
1
仓库
首次出现
1 天前
安全审计
安装于
amp1
cline1
trae1
trae-cn1
opencode1
cursor1
| Metodo | Ruta | Descripcion | Estado |
|---|---|---|---|
| POST | /auth/login | Obtener token de acceso | Implementado |
| POST | /seg-social/alta | Registrar alta de trabajador | Implementado |
| POST | /seg-social/baja | Registrar baja de trabajador | Implementado |
| GET | /seg-social/nss-by-ipf | Consultar NSS por DNI + apellidos | Implementado |
| POST | /certificate | Subir certificado digital p12/pfx | Implementado |
{
naf: "123456789012", // NSS (12 digitos)
ipf: "12345678A", // DNI/NIE
nombre: "Juan",
apellido1: "Garcia",
apellido2: "Lopez",
fecha_nacimiento: "1990-01-15",
sexo: "H", // H = Hombre, M = Mujer
regimen: "0111", // Regimen general
ccc: "28123456789", // CCC empresa (11 digitos)
grupo_cotizacion: "07",
fecha_alta: "2024-01-15",
cno: "5120", // Codigo Nacional de Ocupacion
tipo_contrato: "100",
coeficiente_jornada: "1000", // 1000 = jornada completa
cert_secret: "xxx", // Del certificado digital de la empresa
test: 1 // 1 = modo prueba, 0 = produccion
}
{
naf: "123456789012", // NSS
ipf: "12345678A", // DNI/NIE
fecha_baja: "2024-06-30",
causa_baja: "51", // Codigo causa (51 = baja voluntaria)
ccc: "28123456789",
cert_secret: "xxx",
test: 1
}
try {
const result = await darAlta(datos, certSecret);
return result;
} catch (error) {
if (error.response?.data?.message) {
// Error legible de SALTRA
logger.error({ saltraError: error.response.data }, "Error SALTRA");
throw new Error(`Error SALTRA: ${error.response.data.message}`);
}
throw error;
}
| Concepto | Convencion |
|---|---|
| Token cache | Siempre reutilizar con margen de 5 minutos antes de expiracion |
| Modo test | Forzar test=1 en entornos que NO sean produccion |
| cert_secret | Se obtiene de Company.saltra_cert_secret, se almacena al subir certificado |
| Errores | Parsear response.data.message para errores legibles al usuario |
| Logging | Loguear request y response completos en nivel debug |
| Config | Variables en config.js: SALTRA_API_URL, SALTRA_EMAIL, SALTRA_PASSWORD |
test: 1)Weekly Installs
1
Repository
First Seen
1 day ago
Security Audits
Installed on
amp1
cline1
trae1
trae-cn1
opencode1
cursor1
通过 LiteLLM 代理让 Claude Code 对接 GitHub Copilot 运行 | 高级变通方案指南
31,600 周安装