@feelflow/ffid-sdk 5.31.1 → 6.0.0
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/dist/agency/index.cjs +112 -0
- package/dist/agency/index.d.cts +177 -2
- package/dist/agency/index.d.ts +177 -2
- package/dist/agency/index.js +112 -1
- package/dist/{chunk-3YIX4DFI.cjs → chunk-CI6RBG77.cjs} +6 -2
- package/dist/{chunk-SLYSWV4S.js → chunk-NBBHMLXO.js} +6 -2
- package/dist/components/index.cjs +8 -8
- package/dist/components/index.js +1 -1
- package/dist/{constants-D61jqRIO.d.cts → constants-Ce2eXQtB.d.cts} +5 -2
- package/dist/{constants-D61jqRIO.d.ts → constants-Ce2eXQtB.d.ts} +5 -2
- package/dist/{ffid-client-BTTbDVj7.d.cts → ffid-client-C8XV7lUt.d.cts} +24 -3
- package/dist/{ffid-client-C5lc7SkY.d.ts → ffid-client-CpVixUM3.d.ts} +24 -3
- package/dist/index.cjs +58 -58
- package/dist/index.d.cts +29 -5
- package/dist/index.d.ts +29 -5
- package/dist/index.js +2 -2
- package/dist/legal/index.cjs +16 -1
- package/dist/legal/index.d.cts +33 -6
- package/dist/legal/index.d.ts +33 -6
- package/dist/legal/index.js +16 -1
- package/dist/server/index.cjs +6 -2
- package/dist/server/index.d.cts +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +6 -2
- package/dist/server/test/index.d.cts +1 -1
- package/dist/server/test/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/agency/index.cjs
CHANGED
|
@@ -163,6 +163,14 @@ function createFFIDAgencyClient(config = {}) {
|
|
|
163
163
|
{ method: "DELETE" }
|
|
164
164
|
);
|
|
165
165
|
}
|
|
166
|
+
async function provisionOrganization(agencyId, data) {
|
|
167
|
+
const err = validateIds([agencyId, "agencyId"]);
|
|
168
|
+
if (err) return err;
|
|
169
|
+
return fetchWithCredentials(`/${encodeURIComponent(agencyId)}/organizations/provision`, {
|
|
170
|
+
method: "POST",
|
|
171
|
+
body: JSON.stringify(data)
|
|
172
|
+
});
|
|
173
|
+
}
|
|
166
174
|
async function getSubAgencies(agencyId) {
|
|
167
175
|
const err = validateIds([agencyId, "agencyId"]);
|
|
168
176
|
if (err) return err;
|
|
@@ -290,6 +298,7 @@ function createFFIDAgencyClient(config = {}) {
|
|
|
290
298
|
getOrganizations,
|
|
291
299
|
linkOrganization,
|
|
292
300
|
unlinkOrganization,
|
|
301
|
+
provisionOrganization,
|
|
293
302
|
// Sub-Agencies
|
|
294
303
|
getSubAgencies,
|
|
295
304
|
createSubAgency,
|
|
@@ -316,9 +325,112 @@ function createFFIDAgencyClient(config = {}) {
|
|
|
316
325
|
};
|
|
317
326
|
}
|
|
318
327
|
|
|
328
|
+
// src/agency/ffid-agency-server-client.ts
|
|
329
|
+
var API_PREFIX2 = "/api/v1/ext/agencies";
|
|
330
|
+
var AGENCY_API_KEY_HEADER = "X-Agency-Api-Key";
|
|
331
|
+
var SDK_LOG_PREFIX2 = "[FFID Agency Server SDK]";
|
|
332
|
+
var noopLogger2 = {
|
|
333
|
+
debug: () => {
|
|
334
|
+
},
|
|
335
|
+
info: () => {
|
|
336
|
+
},
|
|
337
|
+
warn: () => {
|
|
338
|
+
},
|
|
339
|
+
error: () => {
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
var consoleLogger2 = {
|
|
343
|
+
debug: (...args) => console.debug(SDK_LOG_PREFIX2, ...args),
|
|
344
|
+
info: (...args) => console.info(SDK_LOG_PREFIX2, ...args),
|
|
345
|
+
warn: (...args) => console.warn(SDK_LOG_PREFIX2, ...args),
|
|
346
|
+
error: (...args) => console.error(SDK_LOG_PREFIX2, ...args)
|
|
347
|
+
};
|
|
348
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
349
|
+
function createFFIDAgencyServerClient(config) {
|
|
350
|
+
const apiKey = config.apiKey?.trim() ?? "";
|
|
351
|
+
if (apiKey === "") {
|
|
352
|
+
throw new Error(
|
|
353
|
+
"createFFIDAgencyServerClient: apiKey is required (set it from an environment variable, never in browser code)"
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
const baseUrl = config.apiBaseUrl ?? chunkMDHKSVLP_cjs.DEFAULT_API_BASE_URL;
|
|
357
|
+
const logger = config.logger ?? (config.debug ? consoleLogger2 : noopLogger2);
|
|
358
|
+
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
359
|
+
async function request(endpoint, body) {
|
|
360
|
+
const url = `${baseUrl}${API_PREFIX2}${endpoint}`;
|
|
361
|
+
let response;
|
|
362
|
+
try {
|
|
363
|
+
response = await fetch(url, {
|
|
364
|
+
method: "POST",
|
|
365
|
+
headers: {
|
|
366
|
+
"Content-Type": "application/json",
|
|
367
|
+
[AGENCY_API_KEY_HEADER]: apiKey
|
|
368
|
+
},
|
|
369
|
+
body: JSON.stringify(body),
|
|
370
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
371
|
+
});
|
|
372
|
+
} catch (error) {
|
|
373
|
+
logger.error("Network error:", { url, error });
|
|
374
|
+
return {
|
|
375
|
+
error: {
|
|
376
|
+
code: FFID_AGENCY_ERROR_CODES.NETWORK_ERROR,
|
|
377
|
+
// タイムアウトも組織が作られた後かもしれない。再試行の前に確認を促す。
|
|
378
|
+
message: `${error instanceof Error ? error.message : "\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F"}\u3002\u7D44\u7E54\u304C\u4F5C\u6210\u3055\u308C\u305F\u53EF\u80FD\u6027\u304C\u3042\u308B\u305F\u3081\u3001\u518D\u8A66\u884C\u524D\u306B\u7D44\u7E54\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044`
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
let payload;
|
|
383
|
+
try {
|
|
384
|
+
payload = await response.json();
|
|
385
|
+
} catch (parseError) {
|
|
386
|
+
logger.error("Parse error:", { url, status: response.status, parseError });
|
|
387
|
+
return {
|
|
388
|
+
error: {
|
|
389
|
+
code: FFID_AGENCY_ERROR_CODES.PARSE_ERROR,
|
|
390
|
+
message: `\u30B5\u30FC\u30D0\u30FC\u304B\u3089\u4E0D\u6B63\u306A\u30EC\u30B9\u30DD\u30F3\u30B9\u3092\u53D7\u4FE1\u3057\u307E\u3057\u305F (status: ${response.status})\u3002\u7D44\u7E54\u304C\u4F5C\u6210\u3055\u308C\u305F\u53EF\u80FD\u6027\u304C\u3042\u308B\u305F\u3081\u3001\u518D\u8A66\u884C\u524D\u306B\u7D44\u7E54\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044`
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
if (payload === null || typeof payload !== "object") {
|
|
395
|
+
logger.error("Malformed response body:", { url, status: response.status });
|
|
396
|
+
return {
|
|
397
|
+
error: {
|
|
398
|
+
code: FFID_AGENCY_ERROR_CODES.PARSE_ERROR,
|
|
399
|
+
message: `\u30B5\u30FC\u30D0\u30FC\u304B\u3089\u4E0D\u6B63\u306A\u30EC\u30B9\u30DD\u30F3\u30B9\u3092\u53D7\u4FE1\u3057\u307E\u3057\u305F (status: ${response.status})`
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const parsed = payload;
|
|
404
|
+
if (!response.ok || parsed.success !== true) {
|
|
405
|
+
return {
|
|
406
|
+
error: {
|
|
407
|
+
code: parsed.error?.code ?? FFID_AGENCY_ERROR_CODES.UNKNOWN_ERROR,
|
|
408
|
+
message: parsed.error?.message ?? `\u30EA\u30AF\u30A8\u30B9\u30C8\u304C\u5931\u6557\u3057\u307E\u3057\u305F (${response.status})`
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
if (parsed.data === void 0) {
|
|
413
|
+
logger.error("Missing data in successful response:", { url });
|
|
414
|
+
return {
|
|
415
|
+
error: {
|
|
416
|
+
code: FFID_AGENCY_ERROR_CODES.UNKNOWN_ERROR,
|
|
417
|
+
message: "\u30B5\u30FC\u30D0\u30FC\u304B\u3089\u30C7\u30FC\u30BF\u304C\u8FD4\u3055\u308C\u307E\u305B\u3093\u3067\u3057\u305F"
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return { data: parsed.data };
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
async provisionCustomerOrganization(data) {
|
|
425
|
+
return request("/organizations/provision", data);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
319
430
|
Object.defineProperty(exports, "DEFAULT_API_BASE_URL", {
|
|
320
431
|
enumerable: true,
|
|
321
432
|
get: function () { return chunkMDHKSVLP_cjs.DEFAULT_API_BASE_URL; }
|
|
322
433
|
});
|
|
323
434
|
exports.FFID_AGENCY_ERROR_CODES = FFID_AGENCY_ERROR_CODES;
|
|
324
435
|
exports.createFFIDAgencyClient = createFFIDAgencyClient;
|
|
436
|
+
exports.createFFIDAgencyServerClient = createFFIDAgencyServerClient;
|
package/dist/agency/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { D as DEFAULT_API_BASE_URL } from '../constants-
|
|
1
|
+
export { D as DEFAULT_API_BASE_URL } from '../constants-Ce2eXQtB.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* FFID Agency SDK Type Definitions
|
|
@@ -101,13 +101,60 @@ interface FFIDAgencyOrganization {
|
|
|
101
101
|
commissionRate: number | null;
|
|
102
102
|
markupRate: number | null;
|
|
103
103
|
markupFixed: number | null;
|
|
104
|
+
/** 組織単位の卸割引率 override(%、0〜100)。null = 代理店デフォルトに従う。 */
|
|
105
|
+
wholesaleDiscountRate: number | null;
|
|
104
106
|
notes: string | null;
|
|
105
107
|
createdAt: string;
|
|
106
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* 顧客組織の代行作成リクエスト(#5143)。
|
|
111
|
+
*/
|
|
112
|
+
interface FFIDProvisionOrganizationRequest {
|
|
113
|
+
/** 組織名 */
|
|
114
|
+
name: string;
|
|
115
|
+
/** 顧客担当者のメールアドレス。この人が組織の owner になる */
|
|
116
|
+
ownerEmail: string;
|
|
117
|
+
/**
|
|
118
|
+
* 組織 ID(slug)。半角英小文字・数字・ハイフンのみ。
|
|
119
|
+
*
|
|
120
|
+
* 省略すると組織名から自動生成される。**指定した場合、既存組織と衝突すると
|
|
121
|
+
* 409 が返り、組織は作成されない**(自動で `acme-2` のような別名に
|
|
122
|
+
* すり替えたりはしない。代理店が顧客に伝えた URL と食い違うため)。
|
|
123
|
+
*/
|
|
124
|
+
slug?: string;
|
|
125
|
+
/** 請求先メールアドレス */
|
|
126
|
+
billingEmail?: string;
|
|
127
|
+
}
|
|
128
|
+
/** 案内メールの送信結果。組織作成の成否とは独立している。 */
|
|
129
|
+
type FFIDWelcomeEmailOutcome = 'sent' | 'failed';
|
|
130
|
+
/**
|
|
131
|
+
* 代行作成の結果(#5143)。
|
|
132
|
+
*/
|
|
133
|
+
interface FFIDProvisionedOrganization {
|
|
134
|
+
id: string;
|
|
135
|
+
name: string;
|
|
136
|
+
slug: string;
|
|
137
|
+
billingEmail: string | null;
|
|
138
|
+
createdAt: string;
|
|
139
|
+
/** owner になった顧客担当者 */
|
|
140
|
+
ownerUserId: string;
|
|
141
|
+
ownerEmail: string;
|
|
142
|
+
/** 顧客が既に FeelFlow ID のアカウントを持っていたか */
|
|
143
|
+
ownerExisted: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* パスワード設定の案内メールの結果。
|
|
146
|
+
*
|
|
147
|
+
* `'failed'` でも**組織と紐付けは作成済み**(メール失敗で巻き戻さない)。
|
|
148
|
+
* この場合は顧客がログインできないので、代理店から再送を促すこと。
|
|
149
|
+
*/
|
|
150
|
+
welcomeEmail: FFIDWelcomeEmailOutcome;
|
|
151
|
+
}
|
|
107
152
|
interface FFIDLinkOrganizationRequest {
|
|
108
153
|
organizationId: string;
|
|
109
154
|
billingOverride?: FFIDAgencyBillingOverride;
|
|
110
155
|
commissionRate?: number;
|
|
156
|
+
/** 組織単位の卸割引率 override(%、0〜100)。省略時 / null は代理店デフォルトに従う。 */
|
|
157
|
+
wholesaleDiscountRate?: number | null;
|
|
111
158
|
notes?: string;
|
|
112
159
|
}
|
|
113
160
|
interface FFIDCreateSubAgencyRequest {
|
|
@@ -133,6 +180,8 @@ interface FFIDAgencyBillingConfig {
|
|
|
133
180
|
paymentTerms: number | null;
|
|
134
181
|
defaultMarkupRate: number | null;
|
|
135
182
|
defaultMarkupFixed: number | null;
|
|
183
|
+
/** 代理店デフォルト卸割引率(%、0〜100)。null = 未設定(定価請求)。 */
|
|
184
|
+
wholesaleDiscountRate: number | null;
|
|
136
185
|
}
|
|
137
186
|
interface FFIDUpdateAgencyBillingRequest {
|
|
138
187
|
billingType?: FFIDAgencyBillingType;
|
|
@@ -140,6 +189,8 @@ interface FFIDUpdateAgencyBillingRequest {
|
|
|
140
189
|
paymentTerms?: number;
|
|
141
190
|
defaultMarkupRate?: number;
|
|
142
191
|
defaultMarkupFixed?: number;
|
|
192
|
+
/** 代理店デフォルト卸割引率(%、0〜100)。null で未設定に戻す。 */
|
|
193
|
+
wholesaleDiscountRate?: number | null;
|
|
143
194
|
}
|
|
144
195
|
interface FFIDAgencyBillingSummary {
|
|
145
196
|
agencyId: string;
|
|
@@ -214,6 +265,16 @@ interface FFIDAgencyClient {
|
|
|
214
265
|
unlinkOrganization(agencyId: string, orgId: string): Promise<FFIDAgencyApiResponse<{
|
|
215
266
|
message: string;
|
|
216
267
|
}>>;
|
|
268
|
+
/**
|
|
269
|
+
* 顧客組織を代行作成する(#5143)。
|
|
270
|
+
*
|
|
271
|
+
* `linkOrganization` が**既存**組織を紐付けるのに対し、こちらは組織そのものを
|
|
272
|
+
* 作る。顧客担当者が最初から owner になり、代理店スタッフは組織のメンバーに
|
|
273
|
+
* ならない。作成後、顧客担当者へパスワード設定の案内メールが送られる。
|
|
274
|
+
*
|
|
275
|
+
* 実行できるのは owner / admin / **sales**(support は 403)。
|
|
276
|
+
*/
|
|
277
|
+
provisionOrganization(agencyId: string, data: FFIDProvisionOrganizationRequest): Promise<FFIDAgencyApiResponse<FFIDProvisionedOrganization>>;
|
|
217
278
|
getSubAgencies(agencyId: string): Promise<FFIDAgencyApiResponse<{
|
|
218
279
|
agencies: FFIDAgency[];
|
|
219
280
|
count: number;
|
|
@@ -292,6 +353,120 @@ type FFIDAgencyApiResponse<T> = {
|
|
|
292
353
|
error: FFIDAgencyError;
|
|
293
354
|
};
|
|
294
355
|
|
|
356
|
+
/**
|
|
357
|
+
* 代理店のサーバー間クライアント(API キー認証)
|
|
358
|
+
*
|
|
359
|
+
* ⚠️ **サーバーサイド専用。ブラウザで使ってはいけない。**
|
|
360
|
+
*
|
|
361
|
+
* このクライアントが使う API キーは、
|
|
362
|
+
* - 任意のメールアドレスに対して FFID アカウントを作れる
|
|
363
|
+
* - 顧客組織を代理店に紐付ける = **売上の計上先を決める**
|
|
364
|
+
*
|
|
365
|
+
* ため、ブラウザに出た時点で第三者が代理店になりすませる。
|
|
366
|
+
*
|
|
367
|
+
* ## なぜ `createFFIDAgencyClient` と別なのか
|
|
368
|
+
*
|
|
369
|
+
* あちらは Cookie 認証(`credentials: 'include'`)でブラウザから使える。
|
|
370
|
+
* 同じファクトリに「キーを渡すとキー認証になる」モードを足すと、ブラウザ用の
|
|
371
|
+
* コードにキーを渡す事故が型で防げない。**別の関数にしておけば、
|
|
372
|
+
* キーを渡せる場所がサーバー専用のモジュールに限定される。**
|
|
373
|
+
*
|
|
374
|
+
* ## agencyId を引数に取らない
|
|
375
|
+
*
|
|
376
|
+
* 代理店はキーそのものから確定する。呼び出し側が渡さないので、他社の代理店 ID
|
|
377
|
+
* を指定するという操作自体が存在しない。
|
|
378
|
+
*
|
|
379
|
+
* @see Issue #5144 (Epic #5137)
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* このクライアントが返しうるエラーコード。
|
|
384
|
+
*
|
|
385
|
+
* `FFIDAgencyErrorCode`(SDK 内部で定義した閉じた集合)には、サーバーが実際に
|
|
386
|
+
* 返す `ORGANIZATION_SLUG_CONFLICT` / `INVALID_ORGANIZATION_SLUG` /
|
|
387
|
+
* `REVOKED_API_KEY` などが含まれていない。閉じた union のふりをすると、
|
|
388
|
+
* 利用者が書いた exhaustive な `switch` が実行時に全部 `default` に落ちる。
|
|
389
|
+
* **開いた集合であることを型で正直に表す。**
|
|
390
|
+
*
|
|
391
|
+
* ⚠️ `types.ts` の `FFIDAgencyServerErrorCode` とは**別物**。あちらは
|
|
392
|
+
* 「サーバー由来コードの閉じた union」で `FFIDAgencyErrorCode` の構成要素。
|
|
393
|
+
* こちらは「このクライアントの `error.code` に載りうる値」。
|
|
394
|
+
*/
|
|
395
|
+
type FFIDAgencyServerClientErrorCode = FFIDAgencyErrorCode | (string & {});
|
|
396
|
+
/** サーバークライアントのエラー。`code` が開いた集合である点だけが違う。 */
|
|
397
|
+
interface FFIDAgencyServerClientError {
|
|
398
|
+
code: FFIDAgencyServerClientErrorCode;
|
|
399
|
+
message: string;
|
|
400
|
+
details?: Record<string, unknown>;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* サーバークライアントの応答。
|
|
404
|
+
*
|
|
405
|
+
* Cookie クライアントの `FFIDAgencyApiResponse` は `code` が閉じた union だが、
|
|
406
|
+
* それは SDK 内部で作るコードしか載らないため。こちらは**サーバーのコードを
|
|
407
|
+
* そのまま通す**ので、型も開いておく必要がある。
|
|
408
|
+
*/
|
|
409
|
+
type FFIDAgencyServerClientResponse<T> = {
|
|
410
|
+
data: T;
|
|
411
|
+
error?: undefined;
|
|
412
|
+
} | {
|
|
413
|
+
data?: undefined;
|
|
414
|
+
error: FFIDAgencyServerClientError;
|
|
415
|
+
};
|
|
416
|
+
interface FFIDAgencyServerClientConfig {
|
|
417
|
+
/**
|
|
418
|
+
* 代理店の API キー。**環境変数から読むこと。**
|
|
419
|
+
* ソースに直書きしたりブラウザへ渡したりしてはいけない。
|
|
420
|
+
*/
|
|
421
|
+
apiKey: string;
|
|
422
|
+
apiBaseUrl?: string;
|
|
423
|
+
logger?: FFIDAgencyLogger;
|
|
424
|
+
/** `true` でコンソールに診断ログを出す(`createFFIDAgencyClient` と同じ)。 */
|
|
425
|
+
debug?: boolean;
|
|
426
|
+
/**
|
|
427
|
+
* リクエストのタイムアウト(ミリ秒)。既定 30 秒。
|
|
428
|
+
*
|
|
429
|
+
* 無いと FFID 側がハングしたときに呼び出し側のハンドラも道連れになる。
|
|
430
|
+
*/
|
|
431
|
+
timeoutMs?: number;
|
|
432
|
+
}
|
|
433
|
+
interface FFIDAgencyServerClient {
|
|
434
|
+
/**
|
|
435
|
+
* 顧客組織を代行作成する。
|
|
436
|
+
*
|
|
437
|
+
* 組織の作成・owner membership・代理店への紐付けはサーバー側で 1 つの
|
|
438
|
+
* トランザクションにまとまっており、途中で失敗しても部分的な状態は残らない。
|
|
439
|
+
*
|
|
440
|
+
* 作成後、顧客担当者にパスワード設定の案内メールが送られる。
|
|
441
|
+
* **`welcomeEmail: 'failed'` でも組織と紐付けは作成済み**(メールの失敗で
|
|
442
|
+
* 作成は巻き戻さない)。その場合は顧客がログインできないので、
|
|
443
|
+
* 別途フォローが要る。
|
|
444
|
+
*
|
|
445
|
+
* @returns 成功時は作成された組織。失敗時は `error`(このクライアントは
|
|
446
|
+
* throw しない — 他の agency メソッドと同じ契約)。
|
|
447
|
+
* すべて 401 だが**コードは原因ごとに違う**(打ち手が違うため):
|
|
448
|
+
* - `MISSING_API_KEY` — ヘッダーが無い
|
|
449
|
+
* - `INVALID_API_KEY_FORMAT` — 値が途中で切れている等
|
|
450
|
+
* - `INVALID_API_KEY` — 該当するキーが無い
|
|
451
|
+
* - `REVOKED_API_KEY` / `EXPIRED_API_KEY` — 再発行が必要
|
|
452
|
+
*
|
|
453
|
+
* そのほか:
|
|
454
|
+
* - スコープ不足 / 代理店が停止中 → `FORBIDDEN`(403)
|
|
455
|
+
* - slug が既存組織と衝突 → `ORGANIZATION_SLUG_CONFLICT`(409、組織は作成されない)
|
|
456
|
+
* - 認証段階の一時障害 → `SERVICE_UNAVAILABLE`(503、**安全に再試行できる**)
|
|
457
|
+
* - `PARSE_ERROR` / `NETWORK_ERROR` — **組織が作成された可能性がある**。
|
|
458
|
+
* 再試行の前に組織一覧を確認すること(#5165 で冪等キーを導入予定)
|
|
459
|
+
*/
|
|
460
|
+
provisionCustomerOrganization(data: FFIDProvisionOrganizationRequest): Promise<FFIDAgencyServerClientResponse<FFIDProvisionedOrganization>>;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* サーバー間クライアントを作る。
|
|
464
|
+
*
|
|
465
|
+
* @throws {Error} `apiKey` が空のとき。認証されないリクエストを送って 401 で
|
|
466
|
+
* 気づくより、初期化時点で止めたほうが原因が明確になる。
|
|
467
|
+
*/
|
|
468
|
+
declare function createFFIDAgencyServerClient(config: FFIDAgencyServerClientConfig): FFIDAgencyServerClient;
|
|
469
|
+
|
|
295
470
|
/**
|
|
296
471
|
* FFID Agency API Client
|
|
297
472
|
*
|
|
@@ -318,4 +493,4 @@ declare const FFID_AGENCY_ERROR_CODES: {
|
|
|
318
493
|
};
|
|
319
494
|
declare function createFFIDAgencyClient(config?: FFIDAgencyClientConfig): FFIDAgencyClient;
|
|
320
495
|
|
|
321
|
-
export { type FFIDAddAgencyMemberRequest, type FFIDAgency, type FFIDAgencyApiResponse, type FFIDAgencyAssetType, type FFIDAgencyBillingConfig, type FFIDAgencyBillingOverride, type FFIDAgencyBillingSummary, type FFIDAgencyBillingType, type FFIDAgencyBrandingSettings, type FFIDAgencyClient, type FFIDAgencyClientConfig, type FFIDAgencyDnsRecord, type FFIDAgencyDomainSettings, type FFIDAgencyEmailSettings, type FFIDAgencyError, type FFIDAgencyErrorCode, type FFIDAgencyHierarchyNode, type FFIDAgencyHierarchyResponse, type FFIDAgencyInvoice, type FFIDAgencyInvoiceStatus, type FFIDAgencyLogger, type FFIDAgencyMember, type FFIDAgencyMemberRole, type FFIDAgencyMemberStatus, type FFIDAgencyOrganization, type FFIDAgencyRevenue, type FFIDAgencySdkErrorCode, type FFIDAgencyServerError, type FFIDAgencyServerErrorCode, type FFIDAgencyServerResponse, type FFIDAgencySettings, type FFIDAgencyStatus, type FFIDCreateSubAgencyRequest, type FFIDLinkOrganizationRequest, type FFIDSetupDomainRequest, type FFIDSslStatus, type FFIDUpdateAgencyBillingRequest, type FFIDUpdateAgencyMemberRequest, type FFIDUpdateAgencyRequest, type FFIDUpdateEmailSettingsRequest, FFID_AGENCY_ERROR_CODES, createFFIDAgencyClient };
|
|
496
|
+
export { type FFIDAddAgencyMemberRequest, type FFIDAgency, type FFIDAgencyApiResponse, type FFIDAgencyAssetType, type FFIDAgencyBillingConfig, type FFIDAgencyBillingOverride, type FFIDAgencyBillingSummary, type FFIDAgencyBillingType, type FFIDAgencyBrandingSettings, type FFIDAgencyClient, type FFIDAgencyClientConfig, type FFIDAgencyDnsRecord, type FFIDAgencyDomainSettings, type FFIDAgencyEmailSettings, type FFIDAgencyError, type FFIDAgencyErrorCode, type FFIDAgencyHierarchyNode, type FFIDAgencyHierarchyResponse, type FFIDAgencyInvoice, type FFIDAgencyInvoiceStatus, type FFIDAgencyLogger, type FFIDAgencyMember, type FFIDAgencyMemberRole, type FFIDAgencyMemberStatus, type FFIDAgencyOrganization, type FFIDAgencyRevenue, type FFIDAgencySdkErrorCode, type FFIDAgencyServerClient, type FFIDAgencyServerClientConfig, type FFIDAgencyServerClientError, type FFIDAgencyServerClientErrorCode, type FFIDAgencyServerClientResponse, type FFIDAgencyServerError, type FFIDAgencyServerErrorCode, type FFIDAgencyServerResponse, type FFIDAgencySettings, type FFIDAgencyStatus, type FFIDCreateSubAgencyRequest, type FFIDLinkOrganizationRequest, type FFIDProvisionOrganizationRequest, type FFIDProvisionedOrganization, type FFIDSetupDomainRequest, type FFIDSslStatus, type FFIDUpdateAgencyBillingRequest, type FFIDUpdateAgencyMemberRequest, type FFIDUpdateAgencyRequest, type FFIDUpdateEmailSettingsRequest, type FFIDWelcomeEmailOutcome, FFID_AGENCY_ERROR_CODES, createFFIDAgencyClient, createFFIDAgencyServerClient };
|
package/dist/agency/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { D as DEFAULT_API_BASE_URL } from '../constants-
|
|
1
|
+
export { D as DEFAULT_API_BASE_URL } from '../constants-Ce2eXQtB.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* FFID Agency SDK Type Definitions
|
|
@@ -101,13 +101,60 @@ interface FFIDAgencyOrganization {
|
|
|
101
101
|
commissionRate: number | null;
|
|
102
102
|
markupRate: number | null;
|
|
103
103
|
markupFixed: number | null;
|
|
104
|
+
/** 組織単位の卸割引率 override(%、0〜100)。null = 代理店デフォルトに従う。 */
|
|
105
|
+
wholesaleDiscountRate: number | null;
|
|
104
106
|
notes: string | null;
|
|
105
107
|
createdAt: string;
|
|
106
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* 顧客組織の代行作成リクエスト(#5143)。
|
|
111
|
+
*/
|
|
112
|
+
interface FFIDProvisionOrganizationRequest {
|
|
113
|
+
/** 組織名 */
|
|
114
|
+
name: string;
|
|
115
|
+
/** 顧客担当者のメールアドレス。この人が組織の owner になる */
|
|
116
|
+
ownerEmail: string;
|
|
117
|
+
/**
|
|
118
|
+
* 組織 ID(slug)。半角英小文字・数字・ハイフンのみ。
|
|
119
|
+
*
|
|
120
|
+
* 省略すると組織名から自動生成される。**指定した場合、既存組織と衝突すると
|
|
121
|
+
* 409 が返り、組織は作成されない**(自動で `acme-2` のような別名に
|
|
122
|
+
* すり替えたりはしない。代理店が顧客に伝えた URL と食い違うため)。
|
|
123
|
+
*/
|
|
124
|
+
slug?: string;
|
|
125
|
+
/** 請求先メールアドレス */
|
|
126
|
+
billingEmail?: string;
|
|
127
|
+
}
|
|
128
|
+
/** 案内メールの送信結果。組織作成の成否とは独立している。 */
|
|
129
|
+
type FFIDWelcomeEmailOutcome = 'sent' | 'failed';
|
|
130
|
+
/**
|
|
131
|
+
* 代行作成の結果(#5143)。
|
|
132
|
+
*/
|
|
133
|
+
interface FFIDProvisionedOrganization {
|
|
134
|
+
id: string;
|
|
135
|
+
name: string;
|
|
136
|
+
slug: string;
|
|
137
|
+
billingEmail: string | null;
|
|
138
|
+
createdAt: string;
|
|
139
|
+
/** owner になった顧客担当者 */
|
|
140
|
+
ownerUserId: string;
|
|
141
|
+
ownerEmail: string;
|
|
142
|
+
/** 顧客が既に FeelFlow ID のアカウントを持っていたか */
|
|
143
|
+
ownerExisted: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* パスワード設定の案内メールの結果。
|
|
146
|
+
*
|
|
147
|
+
* `'failed'` でも**組織と紐付けは作成済み**(メール失敗で巻き戻さない)。
|
|
148
|
+
* この場合は顧客がログインできないので、代理店から再送を促すこと。
|
|
149
|
+
*/
|
|
150
|
+
welcomeEmail: FFIDWelcomeEmailOutcome;
|
|
151
|
+
}
|
|
107
152
|
interface FFIDLinkOrganizationRequest {
|
|
108
153
|
organizationId: string;
|
|
109
154
|
billingOverride?: FFIDAgencyBillingOverride;
|
|
110
155
|
commissionRate?: number;
|
|
156
|
+
/** 組織単位の卸割引率 override(%、0〜100)。省略時 / null は代理店デフォルトに従う。 */
|
|
157
|
+
wholesaleDiscountRate?: number | null;
|
|
111
158
|
notes?: string;
|
|
112
159
|
}
|
|
113
160
|
interface FFIDCreateSubAgencyRequest {
|
|
@@ -133,6 +180,8 @@ interface FFIDAgencyBillingConfig {
|
|
|
133
180
|
paymentTerms: number | null;
|
|
134
181
|
defaultMarkupRate: number | null;
|
|
135
182
|
defaultMarkupFixed: number | null;
|
|
183
|
+
/** 代理店デフォルト卸割引率(%、0〜100)。null = 未設定(定価請求)。 */
|
|
184
|
+
wholesaleDiscountRate: number | null;
|
|
136
185
|
}
|
|
137
186
|
interface FFIDUpdateAgencyBillingRequest {
|
|
138
187
|
billingType?: FFIDAgencyBillingType;
|
|
@@ -140,6 +189,8 @@ interface FFIDUpdateAgencyBillingRequest {
|
|
|
140
189
|
paymentTerms?: number;
|
|
141
190
|
defaultMarkupRate?: number;
|
|
142
191
|
defaultMarkupFixed?: number;
|
|
192
|
+
/** 代理店デフォルト卸割引率(%、0〜100)。null で未設定に戻す。 */
|
|
193
|
+
wholesaleDiscountRate?: number | null;
|
|
143
194
|
}
|
|
144
195
|
interface FFIDAgencyBillingSummary {
|
|
145
196
|
agencyId: string;
|
|
@@ -214,6 +265,16 @@ interface FFIDAgencyClient {
|
|
|
214
265
|
unlinkOrganization(agencyId: string, orgId: string): Promise<FFIDAgencyApiResponse<{
|
|
215
266
|
message: string;
|
|
216
267
|
}>>;
|
|
268
|
+
/**
|
|
269
|
+
* 顧客組織を代行作成する(#5143)。
|
|
270
|
+
*
|
|
271
|
+
* `linkOrganization` が**既存**組織を紐付けるのに対し、こちらは組織そのものを
|
|
272
|
+
* 作る。顧客担当者が最初から owner になり、代理店スタッフは組織のメンバーに
|
|
273
|
+
* ならない。作成後、顧客担当者へパスワード設定の案内メールが送られる。
|
|
274
|
+
*
|
|
275
|
+
* 実行できるのは owner / admin / **sales**(support は 403)。
|
|
276
|
+
*/
|
|
277
|
+
provisionOrganization(agencyId: string, data: FFIDProvisionOrganizationRequest): Promise<FFIDAgencyApiResponse<FFIDProvisionedOrganization>>;
|
|
217
278
|
getSubAgencies(agencyId: string): Promise<FFIDAgencyApiResponse<{
|
|
218
279
|
agencies: FFIDAgency[];
|
|
219
280
|
count: number;
|
|
@@ -292,6 +353,120 @@ type FFIDAgencyApiResponse<T> = {
|
|
|
292
353
|
error: FFIDAgencyError;
|
|
293
354
|
};
|
|
294
355
|
|
|
356
|
+
/**
|
|
357
|
+
* 代理店のサーバー間クライアント(API キー認証)
|
|
358
|
+
*
|
|
359
|
+
* ⚠️ **サーバーサイド専用。ブラウザで使ってはいけない。**
|
|
360
|
+
*
|
|
361
|
+
* このクライアントが使う API キーは、
|
|
362
|
+
* - 任意のメールアドレスに対して FFID アカウントを作れる
|
|
363
|
+
* - 顧客組織を代理店に紐付ける = **売上の計上先を決める**
|
|
364
|
+
*
|
|
365
|
+
* ため、ブラウザに出た時点で第三者が代理店になりすませる。
|
|
366
|
+
*
|
|
367
|
+
* ## なぜ `createFFIDAgencyClient` と別なのか
|
|
368
|
+
*
|
|
369
|
+
* あちらは Cookie 認証(`credentials: 'include'`)でブラウザから使える。
|
|
370
|
+
* 同じファクトリに「キーを渡すとキー認証になる」モードを足すと、ブラウザ用の
|
|
371
|
+
* コードにキーを渡す事故が型で防げない。**別の関数にしておけば、
|
|
372
|
+
* キーを渡せる場所がサーバー専用のモジュールに限定される。**
|
|
373
|
+
*
|
|
374
|
+
* ## agencyId を引数に取らない
|
|
375
|
+
*
|
|
376
|
+
* 代理店はキーそのものから確定する。呼び出し側が渡さないので、他社の代理店 ID
|
|
377
|
+
* を指定するという操作自体が存在しない。
|
|
378
|
+
*
|
|
379
|
+
* @see Issue #5144 (Epic #5137)
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* このクライアントが返しうるエラーコード。
|
|
384
|
+
*
|
|
385
|
+
* `FFIDAgencyErrorCode`(SDK 内部で定義した閉じた集合)には、サーバーが実際に
|
|
386
|
+
* 返す `ORGANIZATION_SLUG_CONFLICT` / `INVALID_ORGANIZATION_SLUG` /
|
|
387
|
+
* `REVOKED_API_KEY` などが含まれていない。閉じた union のふりをすると、
|
|
388
|
+
* 利用者が書いた exhaustive な `switch` が実行時に全部 `default` に落ちる。
|
|
389
|
+
* **開いた集合であることを型で正直に表す。**
|
|
390
|
+
*
|
|
391
|
+
* ⚠️ `types.ts` の `FFIDAgencyServerErrorCode` とは**別物**。あちらは
|
|
392
|
+
* 「サーバー由来コードの閉じた union」で `FFIDAgencyErrorCode` の構成要素。
|
|
393
|
+
* こちらは「このクライアントの `error.code` に載りうる値」。
|
|
394
|
+
*/
|
|
395
|
+
type FFIDAgencyServerClientErrorCode = FFIDAgencyErrorCode | (string & {});
|
|
396
|
+
/** サーバークライアントのエラー。`code` が開いた集合である点だけが違う。 */
|
|
397
|
+
interface FFIDAgencyServerClientError {
|
|
398
|
+
code: FFIDAgencyServerClientErrorCode;
|
|
399
|
+
message: string;
|
|
400
|
+
details?: Record<string, unknown>;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* サーバークライアントの応答。
|
|
404
|
+
*
|
|
405
|
+
* Cookie クライアントの `FFIDAgencyApiResponse` は `code` が閉じた union だが、
|
|
406
|
+
* それは SDK 内部で作るコードしか載らないため。こちらは**サーバーのコードを
|
|
407
|
+
* そのまま通す**ので、型も開いておく必要がある。
|
|
408
|
+
*/
|
|
409
|
+
type FFIDAgencyServerClientResponse<T> = {
|
|
410
|
+
data: T;
|
|
411
|
+
error?: undefined;
|
|
412
|
+
} | {
|
|
413
|
+
data?: undefined;
|
|
414
|
+
error: FFIDAgencyServerClientError;
|
|
415
|
+
};
|
|
416
|
+
interface FFIDAgencyServerClientConfig {
|
|
417
|
+
/**
|
|
418
|
+
* 代理店の API キー。**環境変数から読むこと。**
|
|
419
|
+
* ソースに直書きしたりブラウザへ渡したりしてはいけない。
|
|
420
|
+
*/
|
|
421
|
+
apiKey: string;
|
|
422
|
+
apiBaseUrl?: string;
|
|
423
|
+
logger?: FFIDAgencyLogger;
|
|
424
|
+
/** `true` でコンソールに診断ログを出す(`createFFIDAgencyClient` と同じ)。 */
|
|
425
|
+
debug?: boolean;
|
|
426
|
+
/**
|
|
427
|
+
* リクエストのタイムアウト(ミリ秒)。既定 30 秒。
|
|
428
|
+
*
|
|
429
|
+
* 無いと FFID 側がハングしたときに呼び出し側のハンドラも道連れになる。
|
|
430
|
+
*/
|
|
431
|
+
timeoutMs?: number;
|
|
432
|
+
}
|
|
433
|
+
interface FFIDAgencyServerClient {
|
|
434
|
+
/**
|
|
435
|
+
* 顧客組織を代行作成する。
|
|
436
|
+
*
|
|
437
|
+
* 組織の作成・owner membership・代理店への紐付けはサーバー側で 1 つの
|
|
438
|
+
* トランザクションにまとまっており、途中で失敗しても部分的な状態は残らない。
|
|
439
|
+
*
|
|
440
|
+
* 作成後、顧客担当者にパスワード設定の案内メールが送られる。
|
|
441
|
+
* **`welcomeEmail: 'failed'` でも組織と紐付けは作成済み**(メールの失敗で
|
|
442
|
+
* 作成は巻き戻さない)。その場合は顧客がログインできないので、
|
|
443
|
+
* 別途フォローが要る。
|
|
444
|
+
*
|
|
445
|
+
* @returns 成功時は作成された組織。失敗時は `error`(このクライアントは
|
|
446
|
+
* throw しない — 他の agency メソッドと同じ契約)。
|
|
447
|
+
* すべて 401 だが**コードは原因ごとに違う**(打ち手が違うため):
|
|
448
|
+
* - `MISSING_API_KEY` — ヘッダーが無い
|
|
449
|
+
* - `INVALID_API_KEY_FORMAT` — 値が途中で切れている等
|
|
450
|
+
* - `INVALID_API_KEY` — 該当するキーが無い
|
|
451
|
+
* - `REVOKED_API_KEY` / `EXPIRED_API_KEY` — 再発行が必要
|
|
452
|
+
*
|
|
453
|
+
* そのほか:
|
|
454
|
+
* - スコープ不足 / 代理店が停止中 → `FORBIDDEN`(403)
|
|
455
|
+
* - slug が既存組織と衝突 → `ORGANIZATION_SLUG_CONFLICT`(409、組織は作成されない)
|
|
456
|
+
* - 認証段階の一時障害 → `SERVICE_UNAVAILABLE`(503、**安全に再試行できる**)
|
|
457
|
+
* - `PARSE_ERROR` / `NETWORK_ERROR` — **組織が作成された可能性がある**。
|
|
458
|
+
* 再試行の前に組織一覧を確認すること(#5165 で冪等キーを導入予定)
|
|
459
|
+
*/
|
|
460
|
+
provisionCustomerOrganization(data: FFIDProvisionOrganizationRequest): Promise<FFIDAgencyServerClientResponse<FFIDProvisionedOrganization>>;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* サーバー間クライアントを作る。
|
|
464
|
+
*
|
|
465
|
+
* @throws {Error} `apiKey` が空のとき。認証されないリクエストを送って 401 で
|
|
466
|
+
* 気づくより、初期化時点で止めたほうが原因が明確になる。
|
|
467
|
+
*/
|
|
468
|
+
declare function createFFIDAgencyServerClient(config: FFIDAgencyServerClientConfig): FFIDAgencyServerClient;
|
|
469
|
+
|
|
295
470
|
/**
|
|
296
471
|
* FFID Agency API Client
|
|
297
472
|
*
|
|
@@ -318,4 +493,4 @@ declare const FFID_AGENCY_ERROR_CODES: {
|
|
|
318
493
|
};
|
|
319
494
|
declare function createFFIDAgencyClient(config?: FFIDAgencyClientConfig): FFIDAgencyClient;
|
|
320
495
|
|
|
321
|
-
export { type FFIDAddAgencyMemberRequest, type FFIDAgency, type FFIDAgencyApiResponse, type FFIDAgencyAssetType, type FFIDAgencyBillingConfig, type FFIDAgencyBillingOverride, type FFIDAgencyBillingSummary, type FFIDAgencyBillingType, type FFIDAgencyBrandingSettings, type FFIDAgencyClient, type FFIDAgencyClientConfig, type FFIDAgencyDnsRecord, type FFIDAgencyDomainSettings, type FFIDAgencyEmailSettings, type FFIDAgencyError, type FFIDAgencyErrorCode, type FFIDAgencyHierarchyNode, type FFIDAgencyHierarchyResponse, type FFIDAgencyInvoice, type FFIDAgencyInvoiceStatus, type FFIDAgencyLogger, type FFIDAgencyMember, type FFIDAgencyMemberRole, type FFIDAgencyMemberStatus, type FFIDAgencyOrganization, type FFIDAgencyRevenue, type FFIDAgencySdkErrorCode, type FFIDAgencyServerError, type FFIDAgencyServerErrorCode, type FFIDAgencyServerResponse, type FFIDAgencySettings, type FFIDAgencyStatus, type FFIDCreateSubAgencyRequest, type FFIDLinkOrganizationRequest, type FFIDSetupDomainRequest, type FFIDSslStatus, type FFIDUpdateAgencyBillingRequest, type FFIDUpdateAgencyMemberRequest, type FFIDUpdateAgencyRequest, type FFIDUpdateEmailSettingsRequest, FFID_AGENCY_ERROR_CODES, createFFIDAgencyClient };
|
|
496
|
+
export { type FFIDAddAgencyMemberRequest, type FFIDAgency, type FFIDAgencyApiResponse, type FFIDAgencyAssetType, type FFIDAgencyBillingConfig, type FFIDAgencyBillingOverride, type FFIDAgencyBillingSummary, type FFIDAgencyBillingType, type FFIDAgencyBrandingSettings, type FFIDAgencyClient, type FFIDAgencyClientConfig, type FFIDAgencyDnsRecord, type FFIDAgencyDomainSettings, type FFIDAgencyEmailSettings, type FFIDAgencyError, type FFIDAgencyErrorCode, type FFIDAgencyHierarchyNode, type FFIDAgencyHierarchyResponse, type FFIDAgencyInvoice, type FFIDAgencyInvoiceStatus, type FFIDAgencyLogger, type FFIDAgencyMember, type FFIDAgencyMemberRole, type FFIDAgencyMemberStatus, type FFIDAgencyOrganization, type FFIDAgencyRevenue, type FFIDAgencySdkErrorCode, type FFIDAgencyServerClient, type FFIDAgencyServerClientConfig, type FFIDAgencyServerClientError, type FFIDAgencyServerClientErrorCode, type FFIDAgencyServerClientResponse, type FFIDAgencyServerError, type FFIDAgencyServerErrorCode, type FFIDAgencyServerResponse, type FFIDAgencySettings, type FFIDAgencyStatus, type FFIDCreateSubAgencyRequest, type FFIDLinkOrganizationRequest, type FFIDProvisionOrganizationRequest, type FFIDProvisionedOrganization, type FFIDSetupDomainRequest, type FFIDSslStatus, type FFIDUpdateAgencyBillingRequest, type FFIDUpdateAgencyMemberRequest, type FFIDUpdateAgencyRequest, type FFIDUpdateEmailSettingsRequest, type FFIDWelcomeEmailOutcome, FFID_AGENCY_ERROR_CODES, createFFIDAgencyClient, createFFIDAgencyServerClient };
|