@cronvello/shop-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/README.md +34 -0
- package/dist/browser.cjs +100 -2
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +99 -3
- package/dist/browser.js.map +1 -1
- package/dist/{error-C-cJ6OgX.d.cts → error-C5_qRXMp.d.cts} +54 -1
- package/dist/{error-BFzxyQkW.d.ts → error-Do0kyiZ6.d.ts} +54 -1
- package/dist/index.cjs +100 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +99 -3
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +100 -2
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +99 -3
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/browser.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ShopClientOptions, H as HeaderProvider, a as ShopClient } from './error-
|
|
2
|
-
export { B as BaseUrlProvider, M as MaybePromise, b as SHOP_API_URL, c as ShopApiError, d as ShopAuthType, e as ShopConfigurationError, f as
|
|
1
|
+
import { S as ShopClientOptions, H as HeaderProvider, a as ShopClient } from './error-C5_qRXMp.cjs';
|
|
2
|
+
export { B as BaseUrlProvider, C as CONTRACT_SHA256, M as MaybePromise, b as SHOP_API_URL, c as ShopApiError, d as ShopAuthType, e as ShopConfigurationError, f as ShopContractStatus, g as ShopDiagnoseOptions, h as ShopDiagnosis, i as ShopRequestContext, j as ShopRequestOptions, k as ShopRoute, l as ShopRouteAuth, m as ShopRouteBody, n as ShopRouteInput, o as ShopRouteKey, p as ShopRouteMethod, q as ShopRouteParams, r as ShopRouteQuery, s as ShopRouteResponse, t as ShopRouteResponseData, u as diagnoseShop } from './error-C5_qRXMp.cjs';
|
|
3
3
|
import './index-CIpUb0vL.cjs';
|
|
4
4
|
|
|
5
5
|
type ShopBrowserClientOptions = Omit<ShopClientOptions, "headers"> & {
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as ShopClientOptions, H as HeaderProvider, a as ShopClient } from './error-
|
|
2
|
-
export { B as BaseUrlProvider, M as MaybePromise, b as SHOP_API_URL, c as ShopApiError, d as ShopAuthType, e as ShopConfigurationError, f as
|
|
1
|
+
import { S as ShopClientOptions, H as HeaderProvider, a as ShopClient } from './error-Do0kyiZ6.js';
|
|
2
|
+
export { B as BaseUrlProvider, C as CONTRACT_SHA256, M as MaybePromise, b as SHOP_API_URL, c as ShopApiError, d as ShopAuthType, e as ShopConfigurationError, f as ShopContractStatus, g as ShopDiagnoseOptions, h as ShopDiagnosis, i as ShopRequestContext, j as ShopRequestOptions, k as ShopRoute, l as ShopRouteAuth, m as ShopRouteBody, n as ShopRouteInput, o as ShopRouteKey, p as ShopRouteMethod, q as ShopRouteParams, r as ShopRouteQuery, s as ShopRouteResponse, t as ShopRouteResponseData, u as diagnoseShop } from './error-Do0kyiZ6.js';
|
|
3
3
|
import './index-CIpUb0vL.js';
|
|
4
4
|
|
|
5
5
|
type ShopBrowserClientOptions = Omit<ShopClientOptions, "headers"> & {
|
package/dist/browser.js
CHANGED
|
@@ -5270,7 +5270,7 @@ function createShopClient(options = {}) {
|
|
|
5270
5270
|
const defaultTimeoutMs = options.timeoutMs ?? 3e4;
|
|
5271
5271
|
const defaultRetries = options.retries ?? 2;
|
|
5272
5272
|
const retryDelayMs = options.retryDelayMs ?? 250;
|
|
5273
|
-
async function
|
|
5273
|
+
async function resolveBaseUrl2() {
|
|
5274
5274
|
const value = typeof baseUrl === "function" ? await baseUrl() : baseUrl;
|
|
5275
5275
|
return normalizeBaseUrl(value);
|
|
5276
5276
|
}
|
|
@@ -5292,7 +5292,7 @@ function createShopClient(options = {}) {
|
|
|
5292
5292
|
const body = hasBody ? JSON.stringify(values.body) : void 0;
|
|
5293
5293
|
const retries = Math.max(0, requestOptions.retries ?? defaultRetries);
|
|
5294
5294
|
const canRetry = SAFE_METHODS.has(route.method) || requestOptions.retryUnsafe === true;
|
|
5295
|
-
const resolvedBaseUrl = await
|
|
5295
|
+
const resolvedBaseUrl = await resolveBaseUrl2();
|
|
5296
5296
|
for (let attempt = 0; ; attempt += 1) {
|
|
5297
5297
|
const timeout = createRequestSignal(requestOptions.signal, requestOptions.timeoutMs ?? defaultTimeoutMs);
|
|
5298
5298
|
try {
|
|
@@ -5369,6 +5369,102 @@ function createShopClient(options = {}) {
|
|
|
5369
5369
|
return { baseUrl, request, requestText, requestRaw };
|
|
5370
5370
|
}
|
|
5371
5371
|
|
|
5372
|
+
// src/contract-hash.ts
|
|
5373
|
+
var CONTRACT_SHA256 = "335eed391a2786a4f7f010b056d2a6a5b49d9e1244960a15516a5d77b93693b5";
|
|
5374
|
+
|
|
5375
|
+
// src/client/diagnose.ts
|
|
5376
|
+
var SDK_VERSION = "0.2.0" ;
|
|
5377
|
+
async function resolveBaseUrl(options) {
|
|
5378
|
+
const provider = options.client?.baseUrl ?? options.baseUrl ?? SHOP_API_URL;
|
|
5379
|
+
const value = typeof provider === "function" ? await provider() : provider;
|
|
5380
|
+
return normalizeBaseUrl(value);
|
|
5381
|
+
}
|
|
5382
|
+
async function diagnoseShop(options = {}) {
|
|
5383
|
+
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5384
|
+
const baseUrl = await resolveBaseUrl(options);
|
|
5385
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
5386
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
5387
|
+
const base = {
|
|
5388
|
+
ok: false,
|
|
5389
|
+
baseUrl,
|
|
5390
|
+
sdkVersion: SDK_VERSION,
|
|
5391
|
+
reachable: false,
|
|
5392
|
+
contract: { status: "unknown", sdk: CONTRACT_SHA256, live: null, files: null },
|
|
5393
|
+
problems: [],
|
|
5394
|
+
checkedAt
|
|
5395
|
+
};
|
|
5396
|
+
if (typeof doFetch !== "function") {
|
|
5397
|
+
return { ...base, problems: ["No fetch implementation available; pass `fetch` explicitly."] };
|
|
5398
|
+
}
|
|
5399
|
+
const controller = new AbortController();
|
|
5400
|
+
const onAbort = () => controller.abort(options.signal?.reason);
|
|
5401
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
5402
|
+
if (options.signal?.aborted) controller.abort(options.signal.reason);
|
|
5403
|
+
const timer = setTimeout(() => controller.abort(new Error(`Contract probe timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
5404
|
+
let response;
|
|
5405
|
+
try {
|
|
5406
|
+
response = await doFetch(`${baseUrl}/health/contract`, {
|
|
5407
|
+
method: "GET",
|
|
5408
|
+
headers: { accept: "application/json" },
|
|
5409
|
+
signal: controller.signal
|
|
5410
|
+
});
|
|
5411
|
+
} catch (error) {
|
|
5412
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
5413
|
+
return { ...base, problems: [`node-shop at ${baseUrl} could not be reached: ${detail}`] };
|
|
5414
|
+
} finally {
|
|
5415
|
+
clearTimeout(timer);
|
|
5416
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
5417
|
+
}
|
|
5418
|
+
if (response.status === 404) {
|
|
5419
|
+
return {
|
|
5420
|
+
...base,
|
|
5421
|
+
reachable: true,
|
|
5422
|
+
problems: [
|
|
5423
|
+
`node-shop at ${baseUrl} does not serve GET /health/contract, so the contract cannot be verified. Deploy a node-shop that includes it.`
|
|
5424
|
+
]
|
|
5425
|
+
};
|
|
5426
|
+
}
|
|
5427
|
+
if (!response.ok) {
|
|
5428
|
+
return {
|
|
5429
|
+
...base,
|
|
5430
|
+
reachable: true,
|
|
5431
|
+
problems: [`node-shop at ${baseUrl} answered ${response.status} for GET /health/contract; contract not verified.`]
|
|
5432
|
+
};
|
|
5433
|
+
}
|
|
5434
|
+
let body;
|
|
5435
|
+
try {
|
|
5436
|
+
body = await response.json();
|
|
5437
|
+
} catch {
|
|
5438
|
+
return { ...base, reachable: true, problems: [`node-shop at ${baseUrl} returned a non-JSON contract fingerprint.`] };
|
|
5439
|
+
}
|
|
5440
|
+
const live = typeof body.contractSha256 === "string" && body.contractSha256 ? body.contractSha256 : null;
|
|
5441
|
+
const files = typeof body.files === "number" ? body.files : null;
|
|
5442
|
+
if (!live) {
|
|
5443
|
+
return {
|
|
5444
|
+
...base,
|
|
5445
|
+
reachable: true,
|
|
5446
|
+
contract: { ...base.contract, files },
|
|
5447
|
+
problems: [`node-shop at ${baseUrl} could not compute its own contract fingerprint; contract not verified.`]
|
|
5448
|
+
};
|
|
5449
|
+
}
|
|
5450
|
+
if (live !== CONTRACT_SHA256) {
|
|
5451
|
+
return {
|
|
5452
|
+
...base,
|
|
5453
|
+
reachable: true,
|
|
5454
|
+
contract: { status: "drift", sdk: CONTRACT_SHA256, live, files },
|
|
5455
|
+
problems: [
|
|
5456
|
+
`Contract drift: node-shop at ${baseUrl} speaks ${live.slice(0, 12)}, @cronvello/shop-sdk ${SDK_VERSION} was built against ${CONTRACT_SHA256.slice(0, 12)}. Pin a newer SDK version, or deploy the node-shop the SDK was built from.`
|
|
5457
|
+
]
|
|
5458
|
+
};
|
|
5459
|
+
}
|
|
5460
|
+
return {
|
|
5461
|
+
...base,
|
|
5462
|
+
ok: true,
|
|
5463
|
+
reachable: true,
|
|
5464
|
+
contract: { status: "match", sdk: CONTRACT_SHA256, live, files }
|
|
5465
|
+
};
|
|
5466
|
+
}
|
|
5467
|
+
|
|
5372
5468
|
// src/browser.ts
|
|
5373
5469
|
function createShopBrowserClient(options = {}) {
|
|
5374
5470
|
const configured = options.headers;
|
|
@@ -5385,6 +5481,6 @@ function createShopBrowserClient(options = {}) {
|
|
|
5385
5481
|
});
|
|
5386
5482
|
}
|
|
5387
5483
|
|
|
5388
|
-
export { SHOP_API_URL, ShopApiError, ShopConfigurationError, createShopBrowserClient };
|
|
5484
|
+
export { CONTRACT_SHA256, SHOP_API_URL, ShopApiError, ShopConfigurationError, createShopBrowserClient, diagnoseShop };
|
|
5389
5485
|
//# sourceMappingURL=browser.js.map
|
|
5390
5486
|
//# sourceMappingURL=browser.js.map
|