@taphubhq/sdk-core 0.17.1 → 0.17.3

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/index.cjs CHANGED
@@ -178,7 +178,7 @@ var AgencyPairModule = class {
178
178
  if (args.filter.status !== void 0) filter.status = args.filter.status;
179
179
  variables.filter = filter;
180
180
  }
181
- const body = await this.#graphql.request(
181
+ const body = await this.#graphql.publicRequest(
182
182
  FETCH_AGENCY_PAIRS_QUERY,
183
183
  variables,
184
184
  args?.signal ? { signal: args.signal } : void 0
@@ -2346,77 +2346,82 @@ function createGraphQLTransport(deps) {
2346
2346
  }
2347
2347
  return fetchImpl;
2348
2348
  }
2349
- return {
2350
- async request(query, variables, opts) {
2351
- const fetchImpl = resolveFetch();
2352
- const base = baseUrl.replace(/\/+$/, "");
2353
- const op = extractOp(query);
2354
- const url = `${base}?${op}`;
2355
- const token = getToken();
2356
- const headers = buildHeaders({ token, hasBody: true, agencyId });
2357
- const body = { query };
2358
- if (variables !== void 0) {
2359
- body.variables = variables;
2349
+ async function execute(token, query, variables, opts) {
2350
+ const fetchImpl = resolveFetch();
2351
+ const base = baseUrl.replace(/\/+$/, "");
2352
+ const op = extractOp(query);
2353
+ const url = `${base}?${op}`;
2354
+ const headers = buildHeaders({ token, hasBody: true, agencyId });
2355
+ const body = { query };
2356
+ if (variables !== void 0) {
2357
+ body.variables = variables;
2358
+ }
2359
+ const startedAt = Date.now();
2360
+ let httpStatus = null;
2361
+ let gqlErrors = null;
2362
+ let threw = null;
2363
+ const fireProbe = () => {
2364
+ if (!onRequest) return;
2365
+ try {
2366
+ onRequest({
2367
+ startedAt,
2368
+ endedAt: Date.now(),
2369
+ httpStatus,
2370
+ gqlErrors,
2371
+ threw
2372
+ });
2373
+ } catch {
2360
2374
  }
2361
- const startedAt = Date.now();
2362
- let httpStatus = null;
2363
- let gqlErrors = null;
2364
- let threw = null;
2365
- const fireProbe = () => {
2366
- if (!onRequest) return;
2367
- try {
2368
- onRequest({
2369
- startedAt,
2370
- endedAt: Date.now(),
2371
- httpStatus,
2372
- gqlErrors,
2373
- threw
2374
- });
2375
- } catch {
2376
- }
2377
- };
2375
+ };
2376
+ try {
2377
+ let response;
2378
2378
  try {
2379
- let response;
2380
- try {
2381
- response = await fetchImpl.call(void 0, url, {
2382
- method: "POST",
2383
- headers,
2384
- body: JSON.stringify(body),
2385
- signal: opts?.signal
2386
- });
2387
- } catch (err) {
2388
- threw = err;
2389
- mapNetworkErrorToTaphubError(err);
2390
- }
2391
- httpStatus = response.status;
2392
- let responseBody;
2393
- try {
2394
- responseBody = await response.json();
2395
- } catch {
2396
- throw new TaphubServerError("Invalid response from server", {
2397
- code: "InvalidResponse"
2398
- });
2399
- }
2400
- if (!response.ok) {
2401
- mapGraphQLHttpError(response.status, responseBody);
2402
- }
2403
- const graphqlBody = responseBody;
2404
- if (graphqlBody.errors && graphqlBody.errors.length > 0) {
2405
- gqlErrors = graphqlBody.errors;
2406
- mapGraphQLLevelError(graphqlBody);
2407
- }
2408
- if (graphqlBody.data === void 0 || graphqlBody.data === null) {
2409
- throw new TaphubServerError("Invalid response from server", {
2410
- code: "InvalidResponse"
2411
- });
2412
- }
2413
- return graphqlBody.data;
2379
+ response = await fetchImpl.call(void 0, url, {
2380
+ method: "POST",
2381
+ headers,
2382
+ body: JSON.stringify(body),
2383
+ signal: opts?.signal
2384
+ });
2414
2385
  } catch (err) {
2415
- if (threw === null) threw = err;
2416
- throw err;
2417
- } finally {
2418
- fireProbe();
2386
+ threw = err;
2387
+ mapNetworkErrorToTaphubError(err);
2388
+ }
2389
+ httpStatus = response.status;
2390
+ let responseBody;
2391
+ try {
2392
+ responseBody = await response.json();
2393
+ } catch {
2394
+ throw new TaphubServerError("Invalid response from server", {
2395
+ code: "InvalidResponse"
2396
+ });
2397
+ }
2398
+ if (!response.ok) {
2399
+ mapGraphQLHttpError(response.status, responseBody);
2419
2400
  }
2401
+ const graphqlBody = responseBody;
2402
+ if (graphqlBody.errors && graphqlBody.errors.length > 0) {
2403
+ gqlErrors = graphqlBody.errors;
2404
+ mapGraphQLLevelError(graphqlBody);
2405
+ }
2406
+ if (graphqlBody.data === void 0 || graphqlBody.data === null) {
2407
+ throw new TaphubServerError("Invalid response from server", {
2408
+ code: "InvalidResponse"
2409
+ });
2410
+ }
2411
+ return graphqlBody.data;
2412
+ } catch (err) {
2413
+ if (threw === null) threw = err;
2414
+ throw err;
2415
+ } finally {
2416
+ fireProbe();
2417
+ }
2418
+ }
2419
+ return {
2420
+ request(query, variables, opts) {
2421
+ return execute(getToken(), query, variables, opts);
2422
+ },
2423
+ publicRequest(query, variables, opts) {
2424
+ return execute(null, query, variables, opts);
2420
2425
  }
2421
2426
  };
2422
2427
  }
package/dist/index.d.mts CHANGED
@@ -61,6 +61,14 @@ interface GraphQLRequestOpts {
61
61
  }
62
62
  interface GraphQLTransport {
63
63
  request<T>(query: string, variables?: Record<string, unknown>, opts?: GraphQLRequestOpts): Promise<T>;
64
+ /**
65
+ * Tier 0 anonymous variant of {@link request}: sends `x-builder-code` for
66
+ * tenant scoping but NEVER attaches the JWT, even when one is present. Used
67
+ * by agency-scoped public reads (e.g. `fetchAgencyPairs`) so a logged-in
68
+ * user's JWT cannot override the `x-builder-code` agency on a public read.
69
+ * See main-260518-anon-game-view D1.
70
+ */
71
+ publicRequest<T>(query: string, variables?: Record<string, unknown>, opts?: GraphQLRequestOpts): Promise<T>;
64
72
  }
65
73
 
66
74
  type AgencyPairStatus = 'active' | 'paused' | 'ended';
package/dist/index.d.ts CHANGED
@@ -61,6 +61,14 @@ interface GraphQLRequestOpts {
61
61
  }
62
62
  interface GraphQLTransport {
63
63
  request<T>(query: string, variables?: Record<string, unknown>, opts?: GraphQLRequestOpts): Promise<T>;
64
+ /**
65
+ * Tier 0 anonymous variant of {@link request}: sends `x-builder-code` for
66
+ * tenant scoping but NEVER attaches the JWT, even when one is present. Used
67
+ * by agency-scoped public reads (e.g. `fetchAgencyPairs`) so a logged-in
68
+ * user's JWT cannot override the `x-builder-code` agency on a public read.
69
+ * See main-260518-anon-game-view D1.
70
+ */
71
+ publicRequest<T>(query: string, variables?: Record<string, unknown>, opts?: GraphQLRequestOpts): Promise<T>;
64
72
  }
65
73
 
66
74
  type AgencyPairStatus = 'active' | 'paused' | 'ended';
package/dist/index.js CHANGED
@@ -113,7 +113,7 @@ var AgencyPairModule = class {
113
113
  if (args.filter.status !== void 0) filter.status = args.filter.status;
114
114
  variables.filter = filter;
115
115
  }
116
- const body = await this.#graphql.request(
116
+ const body = await this.#graphql.publicRequest(
117
117
  FETCH_AGENCY_PAIRS_QUERY,
118
118
  variables,
119
119
  args?.signal ? { signal: args.signal } : void 0
@@ -2281,77 +2281,82 @@ function createGraphQLTransport(deps) {
2281
2281
  }
2282
2282
  return fetchImpl;
2283
2283
  }
2284
- return {
2285
- async request(query, variables, opts) {
2286
- const fetchImpl = resolveFetch();
2287
- const base = baseUrl.replace(/\/+$/, "");
2288
- const op = extractOp(query);
2289
- const url = `${base}?${op}`;
2290
- const token = getToken();
2291
- const headers = buildHeaders({ token, hasBody: true, agencyId });
2292
- const body = { query };
2293
- if (variables !== void 0) {
2294
- body.variables = variables;
2284
+ async function execute(token, query, variables, opts) {
2285
+ const fetchImpl = resolveFetch();
2286
+ const base = baseUrl.replace(/\/+$/, "");
2287
+ const op = extractOp(query);
2288
+ const url = `${base}?${op}`;
2289
+ const headers = buildHeaders({ token, hasBody: true, agencyId });
2290
+ const body = { query };
2291
+ if (variables !== void 0) {
2292
+ body.variables = variables;
2293
+ }
2294
+ const startedAt = Date.now();
2295
+ let httpStatus = null;
2296
+ let gqlErrors = null;
2297
+ let threw = null;
2298
+ const fireProbe = () => {
2299
+ if (!onRequest) return;
2300
+ try {
2301
+ onRequest({
2302
+ startedAt,
2303
+ endedAt: Date.now(),
2304
+ httpStatus,
2305
+ gqlErrors,
2306
+ threw
2307
+ });
2308
+ } catch {
2295
2309
  }
2296
- const startedAt = Date.now();
2297
- let httpStatus = null;
2298
- let gqlErrors = null;
2299
- let threw = null;
2300
- const fireProbe = () => {
2301
- if (!onRequest) return;
2302
- try {
2303
- onRequest({
2304
- startedAt,
2305
- endedAt: Date.now(),
2306
- httpStatus,
2307
- gqlErrors,
2308
- threw
2309
- });
2310
- } catch {
2311
- }
2312
- };
2310
+ };
2311
+ try {
2312
+ let response;
2313
2313
  try {
2314
- let response;
2315
- try {
2316
- response = await fetchImpl.call(void 0, url, {
2317
- method: "POST",
2318
- headers,
2319
- body: JSON.stringify(body),
2320
- signal: opts?.signal
2321
- });
2322
- } catch (err) {
2323
- threw = err;
2324
- mapNetworkErrorToTaphubError(err);
2325
- }
2326
- httpStatus = response.status;
2327
- let responseBody;
2328
- try {
2329
- responseBody = await response.json();
2330
- } catch {
2331
- throw new TaphubServerError("Invalid response from server", {
2332
- code: "InvalidResponse"
2333
- });
2334
- }
2335
- if (!response.ok) {
2336
- mapGraphQLHttpError(response.status, responseBody);
2337
- }
2338
- const graphqlBody = responseBody;
2339
- if (graphqlBody.errors && graphqlBody.errors.length > 0) {
2340
- gqlErrors = graphqlBody.errors;
2341
- mapGraphQLLevelError(graphqlBody);
2342
- }
2343
- if (graphqlBody.data === void 0 || graphqlBody.data === null) {
2344
- throw new TaphubServerError("Invalid response from server", {
2345
- code: "InvalidResponse"
2346
- });
2347
- }
2348
- return graphqlBody.data;
2314
+ response = await fetchImpl.call(void 0, url, {
2315
+ method: "POST",
2316
+ headers,
2317
+ body: JSON.stringify(body),
2318
+ signal: opts?.signal
2319
+ });
2349
2320
  } catch (err) {
2350
- if (threw === null) threw = err;
2351
- throw err;
2352
- } finally {
2353
- fireProbe();
2321
+ threw = err;
2322
+ mapNetworkErrorToTaphubError(err);
2323
+ }
2324
+ httpStatus = response.status;
2325
+ let responseBody;
2326
+ try {
2327
+ responseBody = await response.json();
2328
+ } catch {
2329
+ throw new TaphubServerError("Invalid response from server", {
2330
+ code: "InvalidResponse"
2331
+ });
2332
+ }
2333
+ if (!response.ok) {
2334
+ mapGraphQLHttpError(response.status, responseBody);
2354
2335
  }
2336
+ const graphqlBody = responseBody;
2337
+ if (graphqlBody.errors && graphqlBody.errors.length > 0) {
2338
+ gqlErrors = graphqlBody.errors;
2339
+ mapGraphQLLevelError(graphqlBody);
2340
+ }
2341
+ if (graphqlBody.data === void 0 || graphqlBody.data === null) {
2342
+ throw new TaphubServerError("Invalid response from server", {
2343
+ code: "InvalidResponse"
2344
+ });
2345
+ }
2346
+ return graphqlBody.data;
2347
+ } catch (err) {
2348
+ if (threw === null) threw = err;
2349
+ throw err;
2350
+ } finally {
2351
+ fireProbe();
2352
+ }
2353
+ }
2354
+ return {
2355
+ request(query, variables, opts) {
2356
+ return execute(getToken(), query, variables, opts);
2357
+ },
2358
+ publicRequest(query, variables, opts) {
2359
+ return execute(null, query, variables, opts);
2355
2360
  }
2356
2361
  };
2357
2362
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taphubhq/sdk-core",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "description": "Core SDK for building on the TabHub platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",