@biza-gov/center-sdk 0.0.0-stage → 1.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/CHANGELOG.md +36 -0
- package/README.md +209 -3
- package/dist/chunk-HRJMMM7P.mjs +260 -0
- package/dist/client-uAuKf1a3.d.mts +4148 -0
- package/dist/client-uAuKf1a3.d.ts +4148 -0
- package/dist/index.d.mts +65 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +292 -0
- package/dist/index.mjs +18 -0
- package/dist/testing.d.mts +32 -0
- package/dist/testing.d.ts +32 -0
- package/dist/testing.js +331 -0
- package/dist/testing.mjs +56 -0
- package/package.json +54 -4
package/dist/testing.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/testing.ts
|
|
21
|
+
var testing_exports = {};
|
|
22
|
+
__export(testing_exports, {
|
|
23
|
+
createGovCenterMock: () => createGovCenterMock,
|
|
24
|
+
mockResponse: () => mockResponse
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(testing_exports);
|
|
27
|
+
|
|
28
|
+
// src/error.ts
|
|
29
|
+
function codeForStatus(status, requiredScope) {
|
|
30
|
+
if (status === 400 || status === 422) return "VALIDATION";
|
|
31
|
+
if (status === 401) return "UNAUTHORIZED";
|
|
32
|
+
if (status === 403) return requiredScope ? "MISSING_SCOPE" : "FORBIDDEN";
|
|
33
|
+
if (status === 404) return "NOT_FOUND";
|
|
34
|
+
if (status === 409) return "CONFLICT";
|
|
35
|
+
if (status === 429) return "RATE_LIMITED";
|
|
36
|
+
if (status >= 500) return "UPSTREAM";
|
|
37
|
+
return "HTTP_ERROR";
|
|
38
|
+
}
|
|
39
|
+
var GovCenterError = class _GovCenterError extends Error {
|
|
40
|
+
status;
|
|
41
|
+
code;
|
|
42
|
+
requiredScope;
|
|
43
|
+
/** Seconds to wait before retrying, from the Retry-After header. */
|
|
44
|
+
retryAfter;
|
|
45
|
+
requestId;
|
|
46
|
+
details;
|
|
47
|
+
constructor(options) {
|
|
48
|
+
super(options.message);
|
|
49
|
+
this.name = "GovCenterError";
|
|
50
|
+
this.status = options.status;
|
|
51
|
+
this.code = options.code ?? codeForStatus(options.status, options.requiredScope);
|
|
52
|
+
this.requiredScope = options.requiredScope;
|
|
53
|
+
this.retryAfter = options.retryAfter;
|
|
54
|
+
this.requestId = options.requestId;
|
|
55
|
+
this.details = options.details;
|
|
56
|
+
Object.setPrototypeOf(this, _GovCenterError.prototype);
|
|
57
|
+
}
|
|
58
|
+
get isRateLimited() {
|
|
59
|
+
return this.status === 429;
|
|
60
|
+
}
|
|
61
|
+
get isUnauthorized() {
|
|
62
|
+
return this.status === 401;
|
|
63
|
+
}
|
|
64
|
+
get isForbidden() {
|
|
65
|
+
return this.status === 403;
|
|
66
|
+
}
|
|
67
|
+
get isNotFound() {
|
|
68
|
+
return this.status === 404;
|
|
69
|
+
}
|
|
70
|
+
get isServerError() {
|
|
71
|
+
return this.status >= 500;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/retry.ts
|
|
76
|
+
function isRetryableStatus(status) {
|
|
77
|
+
return status === 429 || status === 502 || status === 503 || status === 504;
|
|
78
|
+
}
|
|
79
|
+
async function wait(ms) {
|
|
80
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
81
|
+
}
|
|
82
|
+
function parseRetryAfter(header) {
|
|
83
|
+
if (!header) return void 0;
|
|
84
|
+
const seconds = Number(header);
|
|
85
|
+
if (Number.isFinite(seconds) && seconds >= 0) return seconds;
|
|
86
|
+
const date = Date.parse(header);
|
|
87
|
+
if (!Number.isNaN(date)) return Math.max(0, Math.ceil((date - Date.now()) / 1e3));
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
function calculateBackoff(attempt, baseDelayMs = 300, maxDelayMs = 5e3, retryAfterHeader) {
|
|
91
|
+
const retryAfter = parseRetryAfter(retryAfterHeader);
|
|
92
|
+
if (retryAfter !== void 0) {
|
|
93
|
+
return Math.min(retryAfter * 1e3, maxDelayMs);
|
|
94
|
+
}
|
|
95
|
+
const exp = Math.min(baseDelayMs * Math.pow(2, attempt), maxDelayMs);
|
|
96
|
+
const jitter = exp * (0.8 + Math.random() * 0.4);
|
|
97
|
+
return Math.floor(jitter);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/client.ts
|
|
101
|
+
var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
102
|
+
var GOVCENTER_API_URLS = Object.freeze({
|
|
103
|
+
production: "https://api-auth.govcenter.co",
|
|
104
|
+
uat: "https://uat-api-auth.govcenter.co"
|
|
105
|
+
});
|
|
106
|
+
function readEnvironment(value) {
|
|
107
|
+
if (!value) return null;
|
|
108
|
+
const name = value.trim().toLowerCase();
|
|
109
|
+
if (name === "prod") return "production";
|
|
110
|
+
if (name === "production" || name === "uat") return name;
|
|
111
|
+
throw new Error(`Unknown GovCenter environment "${value}": use "uat" or "production"`);
|
|
112
|
+
}
|
|
113
|
+
function generateRequestId() {
|
|
114
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto && typeof globalThis.crypto.randomUUID === "function") {
|
|
115
|
+
return globalThis.crypto.randomUUID();
|
|
116
|
+
}
|
|
117
|
+
return `gc-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 11)}`;
|
|
118
|
+
}
|
|
119
|
+
function isBrowser() {
|
|
120
|
+
const g = globalThis;
|
|
121
|
+
return typeof g.window !== "undefined" && typeof g.document !== "undefined";
|
|
122
|
+
}
|
|
123
|
+
function needsApiKey(path) {
|
|
124
|
+
return path === "/e-services" || path.startsWith("/e-services/");
|
|
125
|
+
}
|
|
126
|
+
function errorMessage(body, fallback) {
|
|
127
|
+
const message = body?.message;
|
|
128
|
+
if (Array.isArray(message)) return message.join(", ");
|
|
129
|
+
if (typeof message === "string" && message) return message;
|
|
130
|
+
return fallback;
|
|
131
|
+
}
|
|
132
|
+
function createGovCenterClient(config = {}) {
|
|
133
|
+
if (isBrowser() && !config.dangerouslyAllowBrowser) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
"gov-center-sdk runs on the server only: the API key would be visible to every visitor. Call your own backend from the browser instead."
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const env = globalThis.process?.env ?? {};
|
|
139
|
+
const environment = readEnvironment(config.environment ?? env.GOVCENTER_ENV);
|
|
140
|
+
const baseUrl = (config.baseUrl || env.GOVCENTER_API_URL || env.IAM_API_URL || (environment ? GOVCENTER_API_URLS[environment] : "http://localhost:4001")).replace(/\/+$/, "");
|
|
141
|
+
const apiKey = config.apiKey ?? env.E_SERVICE_API_KEY ?? "";
|
|
142
|
+
const apiSecret = config.apiSecret ?? env.E_SERVICE_API_SECRET ?? "";
|
|
143
|
+
const serviceCode = (config.serviceCode ?? env.E_SERVICE_CODE ?? "").trim();
|
|
144
|
+
const timeoutMs = config.timeoutMs ?? 1e4;
|
|
145
|
+
const maxRetries = config.maxRetries ?? 2;
|
|
146
|
+
const customFetch = config.fetch || globalThis.fetch;
|
|
147
|
+
let parsedBase;
|
|
148
|
+
try {
|
|
149
|
+
parsedBase = new URL(baseUrl);
|
|
150
|
+
} catch {
|
|
151
|
+
throw new Error(`Invalid GovCenter baseUrl: ${baseUrl}`);
|
|
152
|
+
}
|
|
153
|
+
if (parsedBase.protocol !== "https:" && !(parsedBase.protocol === "http:" && LOCAL_HOSTS.has(parsedBase.hostname))) {
|
|
154
|
+
throw new Error(`GovCenter baseUrl must use https (http is allowed only for localhost): ${baseUrl}`);
|
|
155
|
+
}
|
|
156
|
+
if (typeof customFetch !== "function") {
|
|
157
|
+
throw new Error(
|
|
158
|
+
"Global fetch is not available in this environment. Please pass a custom fetch to createGovCenterClient({ fetch })."
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
function resolvePath(path, params) {
|
|
162
|
+
let resolved = path.startsWith("/") ? path : `/${path}`;
|
|
163
|
+
if (params) {
|
|
164
|
+
for (const [key, val] of Object.entries(params)) {
|
|
165
|
+
resolved = resolved.replace(new RegExp(`:${key}\\b`, "g"), encodeURIComponent(String(val)));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const missing = resolved.match(/\/:([A-Za-z_][A-Za-z0-9_]*)/);
|
|
169
|
+
if (missing) {
|
|
170
|
+
throw new Error(`Missing path parameter "${missing[1]}" for ${path}`);
|
|
171
|
+
}
|
|
172
|
+
if (baseUrl.endsWith("/v1") && (resolved === "/v1" || resolved.startsWith("/v1/"))) {
|
|
173
|
+
resolved = resolved.slice(3) || "/";
|
|
174
|
+
}
|
|
175
|
+
return resolved;
|
|
176
|
+
}
|
|
177
|
+
function buildUrl(resolvedPath, query) {
|
|
178
|
+
let url = `${baseUrl}${resolvedPath}`;
|
|
179
|
+
if (query) {
|
|
180
|
+
const searchParams = new URLSearchParams();
|
|
181
|
+
for (const [key, val] of Object.entries(query)) {
|
|
182
|
+
if (val === void 0 || val === null) continue;
|
|
183
|
+
searchParams.append(key, Array.isArray(val) ? val.join(",") : String(val));
|
|
184
|
+
}
|
|
185
|
+
const qs = searchParams.toString();
|
|
186
|
+
if (qs) url += (url.includes("?") ? "&" : "?") + qs;
|
|
187
|
+
}
|
|
188
|
+
return url;
|
|
189
|
+
}
|
|
190
|
+
async function executeRequest(method, path, options = {}) {
|
|
191
|
+
const resolvedPath = resolvePath(path, options.params);
|
|
192
|
+
const url = buildUrl(resolvedPath, options.query);
|
|
193
|
+
const requestId = generateRequestId();
|
|
194
|
+
const headers = {
|
|
195
|
+
Accept: "application/json",
|
|
196
|
+
"x-request-id": requestId,
|
|
197
|
+
...options.headers
|
|
198
|
+
};
|
|
199
|
+
if (apiKey && needsApiKey(resolvedPath)) {
|
|
200
|
+
headers["x-api-key"] = apiKey;
|
|
201
|
+
if (serviceCode) headers["x-e-service-code"] = serviceCode;
|
|
202
|
+
}
|
|
203
|
+
if (options.idempotencyKey) {
|
|
204
|
+
headers["Idempotency-Key"] = options.idempotencyKey;
|
|
205
|
+
}
|
|
206
|
+
let requestBody;
|
|
207
|
+
if (options.body !== void 0 && options.body !== null) {
|
|
208
|
+
headers["Content-Type"] = "application/json";
|
|
209
|
+
requestBody = typeof options.body === "string" ? options.body : JSON.stringify(options.body);
|
|
210
|
+
}
|
|
211
|
+
const currentTimeout = options.timeoutMs ?? timeoutMs;
|
|
212
|
+
const canRetry = method === "GET" || Boolean(options.idempotencyKey);
|
|
213
|
+
let attempt = 0;
|
|
214
|
+
while (true) {
|
|
215
|
+
const controller = new AbortController();
|
|
216
|
+
const timer = setTimeout(() => controller.abort(), currentTimeout);
|
|
217
|
+
let response;
|
|
218
|
+
try {
|
|
219
|
+
response = await customFetch(url, { method, headers, body: requestBody, signal: controller.signal });
|
|
220
|
+
} catch (err) {
|
|
221
|
+
clearTimeout(timer);
|
|
222
|
+
const isAbort = err?.name === "AbortError";
|
|
223
|
+
if (canRetry && attempt < maxRetries) {
|
|
224
|
+
await wait(calculateBackoff(attempt));
|
|
225
|
+
attempt++;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
throw new GovCenterError({
|
|
229
|
+
status: 0,
|
|
230
|
+
code: isAbort ? "TIMEOUT" : "NETWORK",
|
|
231
|
+
message: isAbort ? `GovCenter request timeout after ${currentTimeout}ms` : err?.message || "Network request failed",
|
|
232
|
+
requestId
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
clearTimeout(timer);
|
|
236
|
+
if (response.ok) {
|
|
237
|
+
if (response.status === 204) return void 0;
|
|
238
|
+
const text = await response.text();
|
|
239
|
+
return text ? JSON.parse(text) : void 0;
|
|
240
|
+
}
|
|
241
|
+
const retryAfterHeader = response.headers?.get?.("Retry-After") ?? null;
|
|
242
|
+
if (canRetry && isRetryableStatus(response.status) && attempt < maxRetries) {
|
|
243
|
+
await wait(calculateBackoff(attempt, 300, 5e3, retryAfterHeader));
|
|
244
|
+
attempt++;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
let errorBody = void 0;
|
|
248
|
+
try {
|
|
249
|
+
const text = await response.text();
|
|
250
|
+
errorBody = text ? JSON.parse(text) : void 0;
|
|
251
|
+
} catch {
|
|
252
|
+
errorBody = void 0;
|
|
253
|
+
}
|
|
254
|
+
const body = errorBody ?? {};
|
|
255
|
+
const message = errorMessage(errorBody, response.statusText || `Request failed with status ${response.status}`);
|
|
256
|
+
const scopeInMessage = response.status === 403 ? message.match(/missing [\w-]* ?scope:\s*([\w:.-]+)/i)?.[1] : void 0;
|
|
257
|
+
throw new GovCenterError({
|
|
258
|
+
status: response.status,
|
|
259
|
+
message,
|
|
260
|
+
code: typeof body.code === "string" ? body.code : void 0,
|
|
261
|
+
requiredScope: typeof body.requiredScope === "string" ? body.requiredScope : scopeInMessage,
|
|
262
|
+
retryAfter: parseRetryAfter(retryAfterHeader),
|
|
263
|
+
requestId: response.headers?.get?.("x-request-id") || requestId,
|
|
264
|
+
details: errorBody
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const call = (method) => (path, options) => executeRequest(method, path, options);
|
|
269
|
+
return {
|
|
270
|
+
get: call("GET"),
|
|
271
|
+
post: call("POST"),
|
|
272
|
+
patch: call("PATCH"),
|
|
273
|
+
delete: call("DELETE"),
|
|
274
|
+
request: (method, path, options) => executeRequest(method, path, options),
|
|
275
|
+
getConfig: () => Object.freeze({ baseUrl, environment, timeoutMs, maxRetries, hasApiKey: Boolean(apiKey), hasApiSecret: Boolean(apiSecret), serviceCode })
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/testing.ts
|
|
280
|
+
function mockResponse(status, body, headers) {
|
|
281
|
+
return { __mockResponse: true, status, body, headers };
|
|
282
|
+
}
|
|
283
|
+
function compile(key, handler) {
|
|
284
|
+
const [method, path] = key.trim().split(/\s+/, 2);
|
|
285
|
+
if (!method || !path) throw new Error(`Mock route must look like "GET /path": ${key}`);
|
|
286
|
+
const names = [];
|
|
287
|
+
const source = path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, (_, name) => {
|
|
288
|
+
names.push(name);
|
|
289
|
+
return "([^/]+)";
|
|
290
|
+
});
|
|
291
|
+
return { method: method.toUpperCase(), pattern: new RegExp(`^${source}$`), names, handler };
|
|
292
|
+
}
|
|
293
|
+
function createGovCenterMock(routes, config = {}) {
|
|
294
|
+
const compiled = Object.entries(routes).map(([k, h]) => compile(k, h));
|
|
295
|
+
const calls = [];
|
|
296
|
+
const fakeFetch = (async (input, init = {}) => {
|
|
297
|
+
const url = new URL(String(input));
|
|
298
|
+
const method = (init.method || "GET").toUpperCase();
|
|
299
|
+
const headers = { ...init.headers };
|
|
300
|
+
const body = typeof init.body === "string" && init.body ? JSON.parse(init.body) : void 0;
|
|
301
|
+
const query = Object.fromEntries(url.searchParams.entries());
|
|
302
|
+
for (const route of compiled) {
|
|
303
|
+
const m = route.method === method ? url.pathname.match(route.pattern) : null;
|
|
304
|
+
if (!m) continue;
|
|
305
|
+
const params = Object.fromEntries(route.names.map((n, i) => [n, decodeURIComponent(m[i + 1])]));
|
|
306
|
+
const req = { method, path: url.pathname, params, query, body, headers };
|
|
307
|
+
calls.push(req);
|
|
308
|
+
const result = typeof route.handler === "function" ? await route.handler(req) : route.handler;
|
|
309
|
+
const res = result && result.__mockResponse ? result : mockResponse(200, result);
|
|
310
|
+
return new Response(res.body === void 0 ? null : JSON.stringify(res.body), {
|
|
311
|
+
status: res.status,
|
|
312
|
+
headers: { "content-type": "application/json", ...res.headers }
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
calls.push({ method, path: url.pathname, params: {}, query, body, headers });
|
|
316
|
+
return new Response(JSON.stringify({ message: `No mock for ${method} ${url.pathname}` }), { status: 404 });
|
|
317
|
+
});
|
|
318
|
+
const client = createGovCenterClient({
|
|
319
|
+
baseUrl: "http://localhost:4001",
|
|
320
|
+
apiKey: "mock-api-key",
|
|
321
|
+
maxRetries: 0,
|
|
322
|
+
...config,
|
|
323
|
+
fetch: fakeFetch
|
|
324
|
+
});
|
|
325
|
+
return Object.assign(client, { calls });
|
|
326
|
+
}
|
|
327
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
328
|
+
0 && (module.exports = {
|
|
329
|
+
createGovCenterMock,
|
|
330
|
+
mockResponse
|
|
331
|
+
});
|
package/dist/testing.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createGovCenterClient
|
|
3
|
+
} from "./chunk-HRJMMM7P.mjs";
|
|
4
|
+
|
|
5
|
+
// src/testing.ts
|
|
6
|
+
function mockResponse(status, body, headers) {
|
|
7
|
+
return { __mockResponse: true, status, body, headers };
|
|
8
|
+
}
|
|
9
|
+
function compile(key, handler) {
|
|
10
|
+
const [method, path] = key.trim().split(/\s+/, 2);
|
|
11
|
+
if (!method || !path) throw new Error(`Mock route must look like "GET /path": ${key}`);
|
|
12
|
+
const names = [];
|
|
13
|
+
const source = path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/:([A-Za-z_][A-Za-z0-9_]*)/g, (_, name) => {
|
|
14
|
+
names.push(name);
|
|
15
|
+
return "([^/]+)";
|
|
16
|
+
});
|
|
17
|
+
return { method: method.toUpperCase(), pattern: new RegExp(`^${source}$`), names, handler };
|
|
18
|
+
}
|
|
19
|
+
function createGovCenterMock(routes, config = {}) {
|
|
20
|
+
const compiled = Object.entries(routes).map(([k, h]) => compile(k, h));
|
|
21
|
+
const calls = [];
|
|
22
|
+
const fakeFetch = (async (input, init = {}) => {
|
|
23
|
+
const url = new URL(String(input));
|
|
24
|
+
const method = (init.method || "GET").toUpperCase();
|
|
25
|
+
const headers = { ...init.headers };
|
|
26
|
+
const body = typeof init.body === "string" && init.body ? JSON.parse(init.body) : void 0;
|
|
27
|
+
const query = Object.fromEntries(url.searchParams.entries());
|
|
28
|
+
for (const route of compiled) {
|
|
29
|
+
const m = route.method === method ? url.pathname.match(route.pattern) : null;
|
|
30
|
+
if (!m) continue;
|
|
31
|
+
const params = Object.fromEntries(route.names.map((n, i) => [n, decodeURIComponent(m[i + 1])]));
|
|
32
|
+
const req = { method, path: url.pathname, params, query, body, headers };
|
|
33
|
+
calls.push(req);
|
|
34
|
+
const result = typeof route.handler === "function" ? await route.handler(req) : route.handler;
|
|
35
|
+
const res = result && result.__mockResponse ? result : mockResponse(200, result);
|
|
36
|
+
return new Response(res.body === void 0 ? null : JSON.stringify(res.body), {
|
|
37
|
+
status: res.status,
|
|
38
|
+
headers: { "content-type": "application/json", ...res.headers }
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
calls.push({ method, path: url.pathname, params: {}, query, body, headers });
|
|
42
|
+
return new Response(JSON.stringify({ message: `No mock for ${method} ${url.pathname}` }), { status: 404 });
|
|
43
|
+
});
|
|
44
|
+
const client = createGovCenterClient({
|
|
45
|
+
baseUrl: "http://localhost:4001",
|
|
46
|
+
apiKey: "mock-api-key",
|
|
47
|
+
maxRetries: 0,
|
|
48
|
+
...config,
|
|
49
|
+
fetch: fakeFetch
|
|
50
|
+
});
|
|
51
|
+
return Object.assign(client, { calls });
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
createGovCenterMock,
|
|
55
|
+
mockResponse
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@biza-gov/center-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SDK for e-services backend to interact with GovCenter Core APIs",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./testing": {
|
|
15
|
+
"types": "./dist/testing.d.ts",
|
|
16
|
+
"import": "./dist/testing.mjs",
|
|
17
|
+
"require": "./dist/testing.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"CHANGELOG.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts src/testing.ts --format cjs,esm --dts --clean",
|
|
27
|
+
"dev": "tsup src/index.ts src/testing.ts --format cjs,esm --dts --watch",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.check.json",
|
|
29
|
+
"test": "npm run build && node --test __tests__/gov-center-sdk.test.mjs",
|
|
30
|
+
"test:local": "npm run build && node --test __tests__/local.integration.test.mjs",
|
|
31
|
+
"prepublishOnly": "npm run typecheck && npm test",
|
|
32
|
+
"gen:types": "node scripts/gen-types.mjs",
|
|
33
|
+
"build:script": "node scripts/build-script.mjs",
|
|
34
|
+
"test:script": "npm run build:script && node --test __tests__/browser-script.test.mjs"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"gov-center",
|
|
38
|
+
"sdk",
|
|
39
|
+
"e-services",
|
|
40
|
+
"api-client"
|
|
41
|
+
],
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"tag": "latest"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"openapi-typescript": "^7.13.0",
|
|
49
|
+
"tsup": "^8.0.0",
|
|
50
|
+
"typescript": "^5.0.0"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=20"
|
|
54
|
+
},
|
|
55
|
+
"sideEffects": false
|
|
56
|
+
}
|