@gyldendalas/gyldendal-divine-api

中文文档
2.4.0发布于 2026/11/04MITTypeScriptESM + CJS构建来源已验证近 30 天下载 5818
原始使用文档
文档目录5 节
  1. Environments
  2. Local services
  3. Running a mix of local and hosted services
  4. Overrides without touching the application
  5. Every override is reported

Gyldendal Divine API

A collection of API clients for the GU-D department at Gyldendal.

Environments

Every service resolves its base URL from the environment passed to the constructor (the installationpurpose of the TYPO3 installation), unless serviceUrl is given explicitly.

environmentresolves to
productionproduction services
development, testingstaging services
localservices running on this machine, see table below
testthe Playwright mock server on https://localhost:3010/services/<name>

Local services

local is for running the services yourself while developing. The services sit in one reserved 4110-4180 block, ten apart, so a service and its own dependencies (DynamoDB local, its admin UI) stay together and nothing collides with the frontends (3000-3002 nuxt, 3010 mock server), the macOS AirPlay Receiver (5000, 7000), the container defaults the services themselves use (8000, 8001, 5432, 8983) or the ephemeral range (49152 and up). Each service's docker-compose publishes its port on 127.0.0.1 only, and the URLs below say 127.0.0.1 rather than localhost for that reason: localhost resolves to ::1 first on macOS, where an IPv4-only mapping is not listening. The test environment keeps localhost, because the Playwright mock server's certificate is issued for that name.

servicelocal URLsource of the port
user settingshttp://127.0.0.1:4110user_settings_service docker-compose (DynamoDB 4111, admin 4112)
highlighthttp://127.0.0.1:4120systime_highlight_server docker-compose-development (DynamoDB 4121, admin 4122, pgvector 4123)
pdf generatorhttp://127.0.0.1:4130pdf_generation_service docker-compose-development
writing taskhttp://127.0.0.1:4140stepwise_task_server docker-compose-development (DynamoDB 4141, admin 4142)
solr proxyhttp://127.0.0.1:4150solr-proxy docker-compose-development (solr itself 4151)
tagginghttp://127.0.0.1:4160reserved here; the repo has no development compose yet
AI bothttp://127.0.0.1:4170reserved here; ai-bot-service main.py defaults to 3100
cookie consent loghttp://127.0.0.1:4180reserved here; cookie_consent_service compose defaults to 1337
pollyhttp://127.0.0.1:3200systime-appear-polly docker-compose-development; its container port 3000 is taken by nuxt dev. Synthesis needs AWS credentials, and the container's CORS preflight currently rejects the Authorization header this SDK sends
quiz (Gale CMS)https://galecms.test.tibalo.dk/apino local Gale, shared test instance

Gale also has a QA installation, which is not an environment of its own — quiz is the only service that has one. It is exported as GALE_QA_URL and applied as an override, so the URL stays in this package:

import { GALE_QA_URL } from '@gyldendalas/gyldendal-divine-api';

environmentOverrides: { quiz: GALE_QA_URL }

TYPO3 asks for it per site through site.sso.sso_overrides.galeQaEndpointEnabled. It is a testing arrangement, so the caller decides whether to honour it: a constructor override is applied in production too, unlike the ambient ones below.

Running a mix of local and hosted services

environment picks one environment for everything, which is rarely what local development wants: usually one service runs on your machine and the rest should come from staging. environmentOverrides says which environment an individual service resolves in, keyed by the service names in src/services/service_urls.ts:

const divine = {
  environment,          // the installationpurpose, as always
  myAccountId,
  environmentOverrides: { highlight: 'local' }
};

new HighlightService(divine);   // http://127.0.0.1:4120
new TaggingService(divine);     // https://staging-tagging.services.systime.dk

Build that object once where the application starts and hand the same one to every service, so the mix lives in a single place.

Note that it names an environment, not a URL. The override keeps reading the table, so a service that moves — including the local port of the very service you overrode — still moves for you on the next version of this package. That is the whole point of keeping the URLs in here, and a caller who writes a URL down has stepped out of it.

For the endpoints the table cannot know about — a service on a non-standard port, a tunnel, a colleague's branch deploy — an override may be a URL instead:

environmentOverrides: { highlight: 'http://127.0.0.1:9999' }

serviceUrl still works and still beats everything else. It is the right tool for a service this package does not know at all, and the wrong one for local development, where it silently opts you out of every future change to that service's address.

Overrides without touching the application

An override can also come from the machine rather than from the code, which keeps it out of the repository entirely. Per service, either:

  • the environment variable DIVINE_ENV_<SERVICE> — DIVINE_ENV_HIGHLIGHT, DIVINE_ENV_PDF_GENERATOR, and so on;
  • globalThis.__divineEnvironmentOverrides, set by a dev-only Nuxt plugin or an injected script, which is the only one of the two that reaches the browser bundle.

Both take the same values as environmentOverrides. An environmentOverrides entry in the code beats them, the environment variable beats globalThis, and neither is read at all when environment is production: configuration that arrives out of band is a hazard there whatever it happens to say.

Every override is reported

An applied override — from any of the four mechanisms, serviceUrl included — writes a line like this the first time it resolves:

[gyldendal-divine-api] highlight is overridden: resolved to http://127.0.0.1:4120 instead of its "development" endpoint (source: environmentOverrides).

The failure mode all of this has is a forgotten override: an entry that reached a release, or a variable exported three weeks ago and since forgotten. So the notice is not silenced in production, where it matters most, and it names the source, because "highlight is on 127.0.0.1" is a puzzle on its own and stops being one as soon as it says which knob did it.

It is written once per process per distinct override, not once per request, since a warning on every call is a warning nobody reads. Pass onOverride to send it somewhere other than console.warn, which this package writes to nowhere else:

new HighlightService({ ...divine, onOverride: ({ message }) => logger.warn(message) });

版本与发布记录

@gyldendalas/gyldendal-divine-api 共发布 68 个版本,首次发布于 2025/02/17;过去 12 个月发布了 41 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.4.0latest2026/11/0412 天前
2.3.02026/10/2720 天前
2.0.02026/09/241 个月前
2.0.0-rc.4next2026/09/221 个月前
1.2.02026/09/211 个月前
1.1.92026/09/152 个月前

关于 @gyldendalas/gyldendal-divine-api 的常见问题

如何安装 @gyldendalas/gyldendal-divine-api?

在项目目录运行 npm install @gyldendalas/gyldendal-divine-api,或使用 pnpm add / yarn add / bun add。

@gyldendalas/gyldendal-divine-api 支持 TypeScript 吗?

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

@gyldendalas/gyldendal-divine-api 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gyldendalas/gyldendal-divine-api 可以商用吗?

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

@gyldendalas/gyldendal-divine-api 的下载量有多少?

根据 npm 官方下载统计,@gyldendalas/gyldendal-divine-api 在 2026/10/17 – 2026/11/15 这 30 天内被下载 5,818 次,日均约 194 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gyldendalas/gyldendal-divine-api 还在维护吗?

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