@h-ai/reach 1.0.0-beta.6 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -67,6 +67,8 @@ This example uses the development Console provider. It records delivery metadata
67
67
 
68
68
  ### Configuration
69
69
 
70
+ Provider names must be unique; duplicates fail with CONFIG_ERROR before connections open. `close()` waits for initialization and releases its providers, preventing late publication after shutdown.
71
+
70
72
  #### Console (development/tests)
71
73
 
72
74
  ```ts
package/README.ja.md CHANGED
@@ -67,6 +67,8 @@ finally {
67
67
 
68
68
  ### 設定
69
69
 
70
+ Provider 名は一意である必要があり、重複は接続前に CONFIG_ERROR を返します。`close()` は初期化を待って Provider を解放し、終了後の状態やタイマーの再公開を防ぎます。
71
+
70
72
  #### Console(開発・テスト用)
71
73
 
72
74
  ```ts
package/README.md CHANGED
@@ -67,6 +67,8 @@ finally {
67
67
 
68
68
  ### 配置
69
69
 
70
+ Provider 名称必须唯一,重复配置在连接前返回 CONFIG_ERROR。`close()` 等待在途初始化并回收其 Provider;关闭返回后不会迟到发布模块或定时器。
71
+
70
72
  #### Console(开发/测试)
71
73
 
72
74
  ```ts
package/dist/index.d.ts CHANGED
@@ -1314,7 +1314,9 @@ interface ReachFunctions extends SendOperations {
1314
1314
  * }
1315
1315
  * else { const providerMessageId = result.data.messageId }
1316
1316
  * }
1317
- * finally { await reach.close() }
1317
+ * finally {
1318
+ * await reach.close()
1319
+ * }
1318
1320
  * }
1319
1321
  * finally {
1320
1322
  * const closed = await reldb.close()
package/dist/index.js CHANGED
@@ -57,7 +57,8 @@ var en_US_default = {
57
57
  reach_apiResponseTooLarge: "API acknowledgement exceeds the 64 KiB limit",
58
58
  reach_apiResponseInvalid: "API acknowledgement must be empty or a JSON object with an optional messageId string",
59
59
  reach_apiRequestFailed: "API request failed or timed out; delivery is unconfirmed",
60
- reach_apiHttpsRequired: "This API policy requires HTTPS and disallows automatic redirects"
60
+ reach_apiHttpsRequired: "This API policy requires HTTPS and disallows automatic redirects",
61
+ reach_config_providerNameDuplicate: "Provider names must be unique"
61
62
  };
62
63
 
63
64
  // messages/ja-JP.json
@@ -109,7 +110,8 @@ var ja_JP_default = {
109
110
  reach_apiResponseTooLarge: "API \u5FDC\u7B54\u304C 64 KiB \u306E\u4E0A\u9650\u3092\u8D85\u3048\u3066\u3044\u307E\u3059",
110
111
  reach_apiResponseInvalid: "API \u5FDC\u7B54\u306F\u7A7A\u304B\u3001\u7701\u7565\u53EF\u80FD\u306A messageId \u6587\u5B57\u5217\u3092\u6301\u3064 JSON \u30AA\u30D6\u30B8\u30A7\u30AF\u30C8\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059",
111
112
  reach_apiRequestFailed: "API \u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u5931\u6557\u307E\u305F\u306F\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u914D\u4FE1\u7D50\u679C\u306F\u672A\u78BA\u8A8D\u3067\u3059",
112
- reach_apiHttpsRequired: "\u3053\u306E API \u30DD\u30EA\u30B7\u30FC\u3067\u306F HTTPS \u304C\u5FC5\u8981\u3067\u3001\u81EA\u52D5\u30EA\u30C0\u30A4\u30EC\u30AF\u30C8\u306F\u7981\u6B62\u3055\u308C\u3066\u3044\u307E\u3059"
113
+ reach_apiHttpsRequired: "\u3053\u306E API \u30DD\u30EA\u30B7\u30FC\u3067\u306F HTTPS \u304C\u5FC5\u8981\u3067\u3001\u81EA\u52D5\u30EA\u30C0\u30A4\u30EC\u30AF\u30C8\u306F\u7981\u6B62\u3055\u308C\u3066\u3044\u307E\u3059",
114
+ reach_config_providerNameDuplicate: "Provider \u540D\u306F\u4E00\u610F\u3067\u3042\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059"
113
115
  };
114
116
 
115
117
  // messages/zh-CN.json
@@ -161,7 +163,8 @@ var zh_CN_default = {
161
163
  reach_apiResponseTooLarge: "API \u56DE\u6267\u8D85\u8FC7 64 KiB \u4E0A\u9650",
162
164
  reach_apiResponseInvalid: "API \u56DE\u6267\u5FC5\u987B\u4E3A\u7A7A\u6216\u542B\u53EF\u9009 messageId \u5B57\u7B26\u4E32\u7684 JSON \u5BF9\u8C61",
163
165
  reach_apiRequestFailed: "API \u8BF7\u6C42\u5931\u8D25\u6216\u8D85\u65F6\uFF0C\u6295\u9012\u7ED3\u679C\u672A\u786E\u8BA4",
164
- reach_apiHttpsRequired: "\u6B64 API \u7B56\u7565\u8981\u6C42 HTTPS \u4E14\u7981\u6B62\u81EA\u52A8\u91CD\u5B9A\u5411"
166
+ reach_apiHttpsRequired: "\u6B64 API \u7B56\u7565\u8981\u6C42 HTTPS \u4E14\u7981\u6B62\u81EA\u52A8\u91CD\u5B9A\u5411",
167
+ reach_config_providerNameDuplicate: "Provider \u540D\u79F0\u4E0D\u80FD\u91CD\u590D"
165
168
  };
166
169
 
167
170
  // src/reach-i18n.ts
@@ -279,7 +282,7 @@ var TemplateConfigSchema = z.object({
279
282
  });
280
283
  var ReachConfigSchema = z.object({
281
284
  /** Provider 配置列表 */
282
- providers: z.array(ProviderConfigSchema).min(1, reachM("reach_config_providersRequired")),
285
+ providers: z.array(ProviderConfigSchema).min(1, reachM("reach_config_providersRequired")).refine((providers2) => new Set(providers2.map((provider) => provider.name)).size === providers2.length, reachM("reach_config_providerNameDuplicate")),
283
286
  /** 模板配置(通过配置文件注册) */
284
287
  templates: z.array(TemplateConfigSchema).optional(),
285
288
  /** 免打扰配置 */
@@ -1965,6 +1968,8 @@ var templateRegistry = createTemplateRegistry();
1965
1968
  var sendLogRepo = null;
1966
1969
  var templateRepo = null;
1967
1970
  var initInProgress = false;
1971
+ var initCompletion = null;
1972
+ var closeInProgress = null;
1968
1973
  function createProvider(config) {
1969
1974
  switch (config.type) {
1970
1975
  case "console":
@@ -2189,7 +2194,7 @@ var reach = {
2189
2194
  }
2190
2195
  },
2191
2196
  async init(config) {
2192
- if (initInProgress) {
2197
+ if (initInProgress || closeInProgress) {
2193
2198
  logger7.warn("Reach module init already in progress, skipping");
2194
2199
  return err(
2195
2200
  HaiReachError.CONFIG_ERROR,
@@ -2198,9 +2203,11 @@ var reach = {
2198
2203
  }
2199
2204
  initInProgress = true;
2200
2205
  try {
2201
- return await doInit(config);
2206
+ initCompletion = doInit(config);
2207
+ return await initCompletion;
2202
2208
  } finally {
2203
2209
  initInProgress = false;
2210
+ initCompletion = null;
2204
2211
  }
2205
2212
  },
2206
2213
  async send(message) {
@@ -2220,7 +2227,17 @@ var reach = {
2220
2227
  return providers.size > 0;
2221
2228
  },
2222
2229
  async close() {
2223
- await doClose();
2230
+ if (closeInProgress)
2231
+ return closeInProgress;
2232
+ closeInProgress = (async () => {
2233
+ await initCompletion;
2234
+ await doClose();
2235
+ })();
2236
+ try {
2237
+ await closeInProgress;
2238
+ } finally {
2239
+ closeInProgress = null;
2240
+ }
2224
2241
  }
2225
2242
  };
2226
2243