@feelflow/ffid-sdk 0.1.0 → 0.2.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/announcements/index.cjs +109 -0
- package/dist/announcements/index.d.cts +165 -0
- package/dist/announcements/index.d.ts +165 -0
- package/dist/announcements/index.js +106 -0
- package/dist/{chunk-YCMQXJOS.cjs → chunk-A6YJDYIX.cjs} +526 -0
- package/dist/chunk-P4MLCG4T.js +4 -0
- package/dist/chunk-P5PPUZGX.cjs +6 -0
- package/dist/{chunk-A63MX52D.js → chunk-VXBUXOLF.js} +522 -1
- package/dist/components/index.cjs +13 -5
- package/dist/components/index.d.cts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/{index-CtBBLbTn.d.cts → index-B92_OuFc.d.cts} +224 -1
- package/dist/{index-CtBBLbTn.d.ts → index-B92_OuFc.d.ts} +224 -1
- package/dist/index.cjs +31 -11
- package/dist/index.d.cts +59 -4
- package/dist/index.d.ts +59 -4
- package/dist/index.js +2 -2
- package/dist/legal/index.cjs +6 -4
- package/dist/legal/index.d.cts +1 -1
- package/dist/legal/index.d.ts +1 -1
- package/dist/legal/index.js +3 -3
- package/dist/webhooks/index.cjs +251 -0
- package/dist/webhooks/index.d.cts +298 -0
- package/dist/webhooks/index.d.ts +298 -0
- package/dist/webhooks/index.js +237 -0
- package/package.json +21 -3
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkP5PPUZGX_cjs = require('../chunk-P5PPUZGX.cjs');
|
|
4
|
+
|
|
5
|
+
// src/announcements/ffid-announcements-client.ts
|
|
6
|
+
var API_PATH = "/api/v1/announcements";
|
|
7
|
+
var SDK_LOG_PREFIX = "[FFID Announcements SDK]";
|
|
8
|
+
var FFID_ANNOUNCEMENTS_ERROR_CODES = {
|
|
9
|
+
/** Network request failed (fetch threw) */
|
|
10
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
11
|
+
/** Failed to parse server response as JSON */
|
|
12
|
+
PARSE_ERROR: "PARSE_ERROR",
|
|
13
|
+
/** Server returned error without structured error body */
|
|
14
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
15
|
+
};
|
|
16
|
+
var quietLogger = {
|
|
17
|
+
debug: () => {
|
|
18
|
+
},
|
|
19
|
+
info: () => {
|
|
20
|
+
},
|
|
21
|
+
warn: () => {
|
|
22
|
+
},
|
|
23
|
+
error: (...args) => console.error(SDK_LOG_PREFIX, ...args)
|
|
24
|
+
};
|
|
25
|
+
var consoleLogger = {
|
|
26
|
+
debug: (...args) => console.debug(SDK_LOG_PREFIX, ...args),
|
|
27
|
+
info: (...args) => console.info(SDK_LOG_PREFIX, ...args),
|
|
28
|
+
warn: (...args) => console.warn(SDK_LOG_PREFIX, ...args),
|
|
29
|
+
error: (...args) => console.error(SDK_LOG_PREFIX, ...args)
|
|
30
|
+
};
|
|
31
|
+
function createFFIDAnnouncementsClient(config = {}) {
|
|
32
|
+
const baseUrl = config.apiBaseUrl ?? chunkP5PPUZGX_cjs.DEFAULT_API_BASE_URL;
|
|
33
|
+
const logger = config.logger ?? (config.debug ? consoleLogger : quietLogger);
|
|
34
|
+
async function fetchApi(endpoint) {
|
|
35
|
+
const url = `${baseUrl}${endpoint}`;
|
|
36
|
+
logger.debug("Fetching:", url);
|
|
37
|
+
let response;
|
|
38
|
+
try {
|
|
39
|
+
response = await fetch(url, {
|
|
40
|
+
headers: {
|
|
41
|
+
Accept: "application/json"
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.error("Network error:", { url, error });
|
|
46
|
+
return {
|
|
47
|
+
error: {
|
|
48
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.NETWORK_ERROR,
|
|
49
|
+
message: error instanceof Error ? error.message : "\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
let data;
|
|
54
|
+
try {
|
|
55
|
+
data = await response.json();
|
|
56
|
+
} catch (parseError) {
|
|
57
|
+
logger.error("Parse error:", { url, status: response.status, parseError });
|
|
58
|
+
return {
|
|
59
|
+
error: {
|
|
60
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.PARSE_ERROR,
|
|
61
|
+
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})`
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
logger.debug("Response:", response.status, data);
|
|
66
|
+
if (!response.ok || !data.success) {
|
|
67
|
+
return {
|
|
68
|
+
error: data.error ?? {
|
|
69
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.UNKNOWN_ERROR,
|
|
70
|
+
message: "\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F"
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (data.data === void 0) {
|
|
75
|
+
return {
|
|
76
|
+
error: {
|
|
77
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.UNKNOWN_ERROR,
|
|
78
|
+
message: "\u30B5\u30FC\u30D0\u30FC\u304B\u3089\u30C7\u30FC\u30BF\u304C\u8FD4\u3055\u308C\u307E\u305B\u3093\u3067\u3057\u305F"
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return { data: data.data };
|
|
83
|
+
}
|
|
84
|
+
async function listAnnouncements(options = {}) {
|
|
85
|
+
const params = new URLSearchParams();
|
|
86
|
+
if (options.limit !== void 0) {
|
|
87
|
+
const limit = Math.max(0, Math.floor(options.limit));
|
|
88
|
+
params.set("limit", String(limit));
|
|
89
|
+
}
|
|
90
|
+
if (options.offset !== void 0) {
|
|
91
|
+
const offset = Math.max(0, Math.floor(options.offset));
|
|
92
|
+
params.set("offset", String(offset));
|
|
93
|
+
}
|
|
94
|
+
const query = params.toString();
|
|
95
|
+
const endpoint = query ? `${API_PATH}?${query}` : API_PATH;
|
|
96
|
+
return fetchApi(endpoint);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
/** List published announcements */
|
|
100
|
+
listAnnouncements,
|
|
101
|
+
/** Resolved logger instance */
|
|
102
|
+
logger,
|
|
103
|
+
/** API base URL */
|
|
104
|
+
baseUrl
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.FFID_ANNOUNCEMENTS_ERROR_CODES = FFID_ANNOUNCEMENTS_ERROR_CODES;
|
|
109
|
+
exports.createFFIDAnnouncementsClient = createFFIDAnnouncementsClient;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FFID Announcements SDK Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Types for the FeelFlow ID Announcements SDK.
|
|
5
|
+
* Used by client applications to fetch and display announcements.
|
|
6
|
+
* Issue: #286
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Announcement type values.
|
|
10
|
+
* Uses string union with open extension for forward compatibility.
|
|
11
|
+
*/
|
|
12
|
+
type AnnouncementType = 'maintenance.scheduled' | 'maintenance.reminder' | 'maintenance.started' | 'maintenance.completed' | 'incident.detected' | 'incident.resolved' | 'api.deprecation' | 'api.breaking_change' | 'sdk.update_available' | 'security.advisory' | 'billing.payment_reminder' | 'billing.payment_failed' | 'legal.terms_updated' | 'account.security_alert' | (string & {});
|
|
13
|
+
/** Announcement status (only 'published' is visible via public API) */
|
|
14
|
+
type AnnouncementStatus = 'draft' | 'published' | 'archived';
|
|
15
|
+
/** Single announcement returned from the public API */
|
|
16
|
+
interface Announcement {
|
|
17
|
+
/** Announcement ID (UUID) */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Announcement type */
|
|
20
|
+
type: AnnouncementType;
|
|
21
|
+
/** Title */
|
|
22
|
+
title: string;
|
|
23
|
+
/** Content (Markdown) */
|
|
24
|
+
content: string;
|
|
25
|
+
/** Announcement status */
|
|
26
|
+
status: AnnouncementStatus;
|
|
27
|
+
/** Scheduled maintenance start time (ISO 8601) */
|
|
28
|
+
scheduledAt: string | null;
|
|
29
|
+
/** Maintenance duration in minutes */
|
|
30
|
+
durationMinutes: number | null;
|
|
31
|
+
/** Affected service codes */
|
|
32
|
+
affectedServices: string[];
|
|
33
|
+
/** Notification channels */
|
|
34
|
+
channels: string[];
|
|
35
|
+
/** When the announcement was published (ISO 8601) */
|
|
36
|
+
publishedAt: string | null;
|
|
37
|
+
/** Created timestamp (ISO 8601) */
|
|
38
|
+
createdAt: string;
|
|
39
|
+
/** Updated timestamp (ISO 8601) */
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
}
|
|
42
|
+
/** Response from list announcements endpoint */
|
|
43
|
+
interface AnnouncementListResponse {
|
|
44
|
+
/** List of announcements */
|
|
45
|
+
announcements: Announcement[];
|
|
46
|
+
/** Total number of matching announcements */
|
|
47
|
+
total: number;
|
|
48
|
+
}
|
|
49
|
+
/** Options for listing announcements */
|
|
50
|
+
interface ListAnnouncementsOptions {
|
|
51
|
+
/** Number of items to return (server default: 20, server max: 100) */
|
|
52
|
+
limit?: number;
|
|
53
|
+
/** Offset for pagination (default: 0) */
|
|
54
|
+
offset?: number;
|
|
55
|
+
}
|
|
56
|
+
/** Configuration for the FFID Announcements Client */
|
|
57
|
+
interface FFIDAnnouncementsClientConfig {
|
|
58
|
+
/** FFID API base URL (defaults to https://id.feelflow.co.jp) */
|
|
59
|
+
apiBaseUrl?: string | undefined;
|
|
60
|
+
/** Enable debug logging */
|
|
61
|
+
debug?: boolean | undefined;
|
|
62
|
+
/** Custom logger */
|
|
63
|
+
logger?: FFIDAnnouncementsLogger | undefined;
|
|
64
|
+
}
|
|
65
|
+
/** Logger interface for Announcements SDK */
|
|
66
|
+
interface FFIDAnnouncementsLogger {
|
|
67
|
+
debug: (...args: unknown[]) => void;
|
|
68
|
+
info: (...args: unknown[]) => void;
|
|
69
|
+
warn: (...args: unknown[]) => void;
|
|
70
|
+
error: (...args: unknown[]) => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* API response wrapper (discriminated union for type safety)
|
|
74
|
+
*
|
|
75
|
+
* Either data is present (success) or error is present (failure), never both.
|
|
76
|
+
*/
|
|
77
|
+
type FFIDAnnouncementsApiResponse<T> = {
|
|
78
|
+
data: T;
|
|
79
|
+
error?: undefined;
|
|
80
|
+
} | {
|
|
81
|
+
data?: undefined;
|
|
82
|
+
error: FFIDAnnouncementsError;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Known SDK error codes.
|
|
86
|
+
* Uses string union with open extension for forward compatibility with server error codes.
|
|
87
|
+
*/
|
|
88
|
+
type FFIDAnnouncementsErrorCode = 'NETWORK_ERROR' | 'PARSE_ERROR' | 'UNKNOWN_ERROR' | (string & {});
|
|
89
|
+
/** Error from the Announcements SDK */
|
|
90
|
+
interface FFIDAnnouncementsError {
|
|
91
|
+
/** Error code (known SDK codes provide autocomplete; server codes also accepted) */
|
|
92
|
+
code: FFIDAnnouncementsErrorCode;
|
|
93
|
+
/** Human-readable error message */
|
|
94
|
+
message: string;
|
|
95
|
+
}
|
|
96
|
+
/** Server response envelope */
|
|
97
|
+
type FFIDAnnouncementsServerResponse<T> = {
|
|
98
|
+
success: true;
|
|
99
|
+
data: T;
|
|
100
|
+
error?: undefined;
|
|
101
|
+
} | {
|
|
102
|
+
success: false;
|
|
103
|
+
data?: undefined;
|
|
104
|
+
error?: {
|
|
105
|
+
code: string;
|
|
106
|
+
message: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* FFID Announcements API Client
|
|
112
|
+
*
|
|
113
|
+
* Handles API communication for public announcements.
|
|
114
|
+
* No authentication required - this is a public endpoint.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { createFFIDAnnouncementsClient } from '@feelflow/ffid-sdk/announcements'
|
|
119
|
+
*
|
|
120
|
+
* const client = createFFIDAnnouncementsClient({
|
|
121
|
+
* apiBaseUrl: 'https://id.feelflow.co.jp',
|
|
122
|
+
* })
|
|
123
|
+
*
|
|
124
|
+
* const { data, error } = await client.listAnnouncements({ limit: 10 })
|
|
125
|
+
* if (data) {
|
|
126
|
+
* console.log(`Found ${data.total} announcements`)
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Error codes used by the Announcements SDK
|
|
133
|
+
*/
|
|
134
|
+
declare const FFID_ANNOUNCEMENTS_ERROR_CODES: {
|
|
135
|
+
/** Network request failed (fetch threw) */
|
|
136
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
137
|
+
/** Failed to parse server response as JSON */
|
|
138
|
+
readonly PARSE_ERROR: "PARSE_ERROR";
|
|
139
|
+
/** Server returned error without structured error body */
|
|
140
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Creates an FFID Announcements API client instance
|
|
144
|
+
*
|
|
145
|
+
* @param config - Client configuration (optional, uses defaults)
|
|
146
|
+
* @returns Announcements client instance
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const client = createFFIDAnnouncementsClient()
|
|
151
|
+
* const { data, error } = await client.listAnnouncements()
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
declare function createFFIDAnnouncementsClient(config?: FFIDAnnouncementsClientConfig): {
|
|
155
|
+
/** List published announcements */
|
|
156
|
+
listAnnouncements: (options?: ListAnnouncementsOptions) => Promise<FFIDAnnouncementsApiResponse<AnnouncementListResponse>>;
|
|
157
|
+
/** Resolved logger instance */
|
|
158
|
+
logger: FFIDAnnouncementsLogger;
|
|
159
|
+
/** API base URL */
|
|
160
|
+
baseUrl: string;
|
|
161
|
+
};
|
|
162
|
+
/** Type of the FFID Announcements client */
|
|
163
|
+
type FFIDAnnouncementsClient = ReturnType<typeof createFFIDAnnouncementsClient>;
|
|
164
|
+
|
|
165
|
+
export { type Announcement, type AnnouncementListResponse, type AnnouncementStatus, type AnnouncementType, type FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, type FFIDAnnouncementsClientConfig, type FFIDAnnouncementsError, type FFIDAnnouncementsErrorCode, type FFIDAnnouncementsLogger, type FFIDAnnouncementsServerResponse, FFID_ANNOUNCEMENTS_ERROR_CODES, type ListAnnouncementsOptions, createFFIDAnnouncementsClient };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FFID Announcements SDK Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Types for the FeelFlow ID Announcements SDK.
|
|
5
|
+
* Used by client applications to fetch and display announcements.
|
|
6
|
+
* Issue: #286
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Announcement type values.
|
|
10
|
+
* Uses string union with open extension for forward compatibility.
|
|
11
|
+
*/
|
|
12
|
+
type AnnouncementType = 'maintenance.scheduled' | 'maintenance.reminder' | 'maintenance.started' | 'maintenance.completed' | 'incident.detected' | 'incident.resolved' | 'api.deprecation' | 'api.breaking_change' | 'sdk.update_available' | 'security.advisory' | 'billing.payment_reminder' | 'billing.payment_failed' | 'legal.terms_updated' | 'account.security_alert' | (string & {});
|
|
13
|
+
/** Announcement status (only 'published' is visible via public API) */
|
|
14
|
+
type AnnouncementStatus = 'draft' | 'published' | 'archived';
|
|
15
|
+
/** Single announcement returned from the public API */
|
|
16
|
+
interface Announcement {
|
|
17
|
+
/** Announcement ID (UUID) */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Announcement type */
|
|
20
|
+
type: AnnouncementType;
|
|
21
|
+
/** Title */
|
|
22
|
+
title: string;
|
|
23
|
+
/** Content (Markdown) */
|
|
24
|
+
content: string;
|
|
25
|
+
/** Announcement status */
|
|
26
|
+
status: AnnouncementStatus;
|
|
27
|
+
/** Scheduled maintenance start time (ISO 8601) */
|
|
28
|
+
scheduledAt: string | null;
|
|
29
|
+
/** Maintenance duration in minutes */
|
|
30
|
+
durationMinutes: number | null;
|
|
31
|
+
/** Affected service codes */
|
|
32
|
+
affectedServices: string[];
|
|
33
|
+
/** Notification channels */
|
|
34
|
+
channels: string[];
|
|
35
|
+
/** When the announcement was published (ISO 8601) */
|
|
36
|
+
publishedAt: string | null;
|
|
37
|
+
/** Created timestamp (ISO 8601) */
|
|
38
|
+
createdAt: string;
|
|
39
|
+
/** Updated timestamp (ISO 8601) */
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
}
|
|
42
|
+
/** Response from list announcements endpoint */
|
|
43
|
+
interface AnnouncementListResponse {
|
|
44
|
+
/** List of announcements */
|
|
45
|
+
announcements: Announcement[];
|
|
46
|
+
/** Total number of matching announcements */
|
|
47
|
+
total: number;
|
|
48
|
+
}
|
|
49
|
+
/** Options for listing announcements */
|
|
50
|
+
interface ListAnnouncementsOptions {
|
|
51
|
+
/** Number of items to return (server default: 20, server max: 100) */
|
|
52
|
+
limit?: number;
|
|
53
|
+
/** Offset for pagination (default: 0) */
|
|
54
|
+
offset?: number;
|
|
55
|
+
}
|
|
56
|
+
/** Configuration for the FFID Announcements Client */
|
|
57
|
+
interface FFIDAnnouncementsClientConfig {
|
|
58
|
+
/** FFID API base URL (defaults to https://id.feelflow.co.jp) */
|
|
59
|
+
apiBaseUrl?: string | undefined;
|
|
60
|
+
/** Enable debug logging */
|
|
61
|
+
debug?: boolean | undefined;
|
|
62
|
+
/** Custom logger */
|
|
63
|
+
logger?: FFIDAnnouncementsLogger | undefined;
|
|
64
|
+
}
|
|
65
|
+
/** Logger interface for Announcements SDK */
|
|
66
|
+
interface FFIDAnnouncementsLogger {
|
|
67
|
+
debug: (...args: unknown[]) => void;
|
|
68
|
+
info: (...args: unknown[]) => void;
|
|
69
|
+
warn: (...args: unknown[]) => void;
|
|
70
|
+
error: (...args: unknown[]) => void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* API response wrapper (discriminated union for type safety)
|
|
74
|
+
*
|
|
75
|
+
* Either data is present (success) or error is present (failure), never both.
|
|
76
|
+
*/
|
|
77
|
+
type FFIDAnnouncementsApiResponse<T> = {
|
|
78
|
+
data: T;
|
|
79
|
+
error?: undefined;
|
|
80
|
+
} | {
|
|
81
|
+
data?: undefined;
|
|
82
|
+
error: FFIDAnnouncementsError;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Known SDK error codes.
|
|
86
|
+
* Uses string union with open extension for forward compatibility with server error codes.
|
|
87
|
+
*/
|
|
88
|
+
type FFIDAnnouncementsErrorCode = 'NETWORK_ERROR' | 'PARSE_ERROR' | 'UNKNOWN_ERROR' | (string & {});
|
|
89
|
+
/** Error from the Announcements SDK */
|
|
90
|
+
interface FFIDAnnouncementsError {
|
|
91
|
+
/** Error code (known SDK codes provide autocomplete; server codes also accepted) */
|
|
92
|
+
code: FFIDAnnouncementsErrorCode;
|
|
93
|
+
/** Human-readable error message */
|
|
94
|
+
message: string;
|
|
95
|
+
}
|
|
96
|
+
/** Server response envelope */
|
|
97
|
+
type FFIDAnnouncementsServerResponse<T> = {
|
|
98
|
+
success: true;
|
|
99
|
+
data: T;
|
|
100
|
+
error?: undefined;
|
|
101
|
+
} | {
|
|
102
|
+
success: false;
|
|
103
|
+
data?: undefined;
|
|
104
|
+
error?: {
|
|
105
|
+
code: string;
|
|
106
|
+
message: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* FFID Announcements API Client
|
|
112
|
+
*
|
|
113
|
+
* Handles API communication for public announcements.
|
|
114
|
+
* No authentication required - this is a public endpoint.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { createFFIDAnnouncementsClient } from '@feelflow/ffid-sdk/announcements'
|
|
119
|
+
*
|
|
120
|
+
* const client = createFFIDAnnouncementsClient({
|
|
121
|
+
* apiBaseUrl: 'https://id.feelflow.co.jp',
|
|
122
|
+
* })
|
|
123
|
+
*
|
|
124
|
+
* const { data, error } = await client.listAnnouncements({ limit: 10 })
|
|
125
|
+
* if (data) {
|
|
126
|
+
* console.log(`Found ${data.total} announcements`)
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Error codes used by the Announcements SDK
|
|
133
|
+
*/
|
|
134
|
+
declare const FFID_ANNOUNCEMENTS_ERROR_CODES: {
|
|
135
|
+
/** Network request failed (fetch threw) */
|
|
136
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
137
|
+
/** Failed to parse server response as JSON */
|
|
138
|
+
readonly PARSE_ERROR: "PARSE_ERROR";
|
|
139
|
+
/** Server returned error without structured error body */
|
|
140
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Creates an FFID Announcements API client instance
|
|
144
|
+
*
|
|
145
|
+
* @param config - Client configuration (optional, uses defaults)
|
|
146
|
+
* @returns Announcements client instance
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const client = createFFIDAnnouncementsClient()
|
|
151
|
+
* const { data, error } = await client.listAnnouncements()
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
declare function createFFIDAnnouncementsClient(config?: FFIDAnnouncementsClientConfig): {
|
|
155
|
+
/** List published announcements */
|
|
156
|
+
listAnnouncements: (options?: ListAnnouncementsOptions) => Promise<FFIDAnnouncementsApiResponse<AnnouncementListResponse>>;
|
|
157
|
+
/** Resolved logger instance */
|
|
158
|
+
logger: FFIDAnnouncementsLogger;
|
|
159
|
+
/** API base URL */
|
|
160
|
+
baseUrl: string;
|
|
161
|
+
};
|
|
162
|
+
/** Type of the FFID Announcements client */
|
|
163
|
+
type FFIDAnnouncementsClient = ReturnType<typeof createFFIDAnnouncementsClient>;
|
|
164
|
+
|
|
165
|
+
export { type Announcement, type AnnouncementListResponse, type AnnouncementStatus, type AnnouncementType, type FFIDAnnouncementsApiResponse, type FFIDAnnouncementsClient, type FFIDAnnouncementsClientConfig, type FFIDAnnouncementsError, type FFIDAnnouncementsErrorCode, type FFIDAnnouncementsLogger, type FFIDAnnouncementsServerResponse, FFID_ANNOUNCEMENTS_ERROR_CODES, type ListAnnouncementsOptions, createFFIDAnnouncementsClient };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { DEFAULT_API_BASE_URL } from '../chunk-P4MLCG4T.js';
|
|
2
|
+
|
|
3
|
+
// src/announcements/ffid-announcements-client.ts
|
|
4
|
+
var API_PATH = "/api/v1/announcements";
|
|
5
|
+
var SDK_LOG_PREFIX = "[FFID Announcements SDK]";
|
|
6
|
+
var FFID_ANNOUNCEMENTS_ERROR_CODES = {
|
|
7
|
+
/** Network request failed (fetch threw) */
|
|
8
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
9
|
+
/** Failed to parse server response as JSON */
|
|
10
|
+
PARSE_ERROR: "PARSE_ERROR",
|
|
11
|
+
/** Server returned error without structured error body */
|
|
12
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
13
|
+
};
|
|
14
|
+
var quietLogger = {
|
|
15
|
+
debug: () => {
|
|
16
|
+
},
|
|
17
|
+
info: () => {
|
|
18
|
+
},
|
|
19
|
+
warn: () => {
|
|
20
|
+
},
|
|
21
|
+
error: (...args) => console.error(SDK_LOG_PREFIX, ...args)
|
|
22
|
+
};
|
|
23
|
+
var consoleLogger = {
|
|
24
|
+
debug: (...args) => console.debug(SDK_LOG_PREFIX, ...args),
|
|
25
|
+
info: (...args) => console.info(SDK_LOG_PREFIX, ...args),
|
|
26
|
+
warn: (...args) => console.warn(SDK_LOG_PREFIX, ...args),
|
|
27
|
+
error: (...args) => console.error(SDK_LOG_PREFIX, ...args)
|
|
28
|
+
};
|
|
29
|
+
function createFFIDAnnouncementsClient(config = {}) {
|
|
30
|
+
const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
|
|
31
|
+
const logger = config.logger ?? (config.debug ? consoleLogger : quietLogger);
|
|
32
|
+
async function fetchApi(endpoint) {
|
|
33
|
+
const url = `${baseUrl}${endpoint}`;
|
|
34
|
+
logger.debug("Fetching:", url);
|
|
35
|
+
let response;
|
|
36
|
+
try {
|
|
37
|
+
response = await fetch(url, {
|
|
38
|
+
headers: {
|
|
39
|
+
Accept: "application/json"
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} catch (error) {
|
|
43
|
+
logger.error("Network error:", { url, error });
|
|
44
|
+
return {
|
|
45
|
+
error: {
|
|
46
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.NETWORK_ERROR,
|
|
47
|
+
message: error instanceof Error ? error.message : "\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F"
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
let data;
|
|
52
|
+
try {
|
|
53
|
+
data = await response.json();
|
|
54
|
+
} catch (parseError) {
|
|
55
|
+
logger.error("Parse error:", { url, status: response.status, parseError });
|
|
56
|
+
return {
|
|
57
|
+
error: {
|
|
58
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.PARSE_ERROR,
|
|
59
|
+
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})`
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
logger.debug("Response:", response.status, data);
|
|
64
|
+
if (!response.ok || !data.success) {
|
|
65
|
+
return {
|
|
66
|
+
error: data.error ?? {
|
|
67
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.UNKNOWN_ERROR,
|
|
68
|
+
message: "\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F"
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (data.data === void 0) {
|
|
73
|
+
return {
|
|
74
|
+
error: {
|
|
75
|
+
code: FFID_ANNOUNCEMENTS_ERROR_CODES.UNKNOWN_ERROR,
|
|
76
|
+
message: "\u30B5\u30FC\u30D0\u30FC\u304B\u3089\u30C7\u30FC\u30BF\u304C\u8FD4\u3055\u308C\u307E\u305B\u3093\u3067\u3057\u305F"
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return { data: data.data };
|
|
81
|
+
}
|
|
82
|
+
async function listAnnouncements(options = {}) {
|
|
83
|
+
const params = new URLSearchParams();
|
|
84
|
+
if (options.limit !== void 0) {
|
|
85
|
+
const limit = Math.max(0, Math.floor(options.limit));
|
|
86
|
+
params.set("limit", String(limit));
|
|
87
|
+
}
|
|
88
|
+
if (options.offset !== void 0) {
|
|
89
|
+
const offset = Math.max(0, Math.floor(options.offset));
|
|
90
|
+
params.set("offset", String(offset));
|
|
91
|
+
}
|
|
92
|
+
const query = params.toString();
|
|
93
|
+
const endpoint = query ? `${API_PATH}?${query}` : API_PATH;
|
|
94
|
+
return fetchApi(endpoint);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
/** List published announcements */
|
|
98
|
+
listAnnouncements,
|
|
99
|
+
/** Resolved logger instance */
|
|
100
|
+
logger,
|
|
101
|
+
/** API base URL */
|
|
102
|
+
baseUrl
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { FFID_ANNOUNCEMENTS_ERROR_CODES, createFFIDAnnouncementsClient };
|