@perstack/api-client 0.0.33 → 0.0.35

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/v1/index.js CHANGED
@@ -1159,8 +1159,8 @@ async function getWorkspaceItem(input, client) {
1159
1159
  };
1160
1160
  }
1161
1161
  var getWorkspaceItemsInput = z.object({
1162
- take: z.union([z.number(), z.string().transform((value) => Number.parseInt(value))]).optional(),
1163
- skip: z.union([z.number(), z.string().transform((value) => Number.parseInt(value))]).optional()
1162
+ take: z.union([z.number(), z.string().transform((value) => Number.parseInt(value, 10))]).optional(),
1163
+ skip: z.union([z.number(), z.string().transform((value) => Number.parseInt(value, 10))]).optional()
1164
1164
  });
1165
1165
  var getWorkspaceItemsResponseSchema = z.object({
1166
1166
  data: z.object({
@@ -1561,31 +1561,55 @@ var ApiV1Client = class {
1561
1561
  baseUrl;
1562
1562
  apiKey;
1563
1563
  constructor(config) {
1564
+ if (config?.baseUrl && !config.baseUrl.startsWith("https://")) {
1565
+ throw new Error("API baseUrl must use HTTPS");
1566
+ }
1564
1567
  this.baseUrl = config?.baseUrl ? config.baseUrl : "https://api.perstack.ai";
1565
1568
  this.apiKey = config?.apiKey;
1566
1569
  }
1567
- async request(endpoint, init) {
1570
+ async request(endpoint, init, schema) {
1571
+ if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
1572
+ const endpointUrl = new URL(endpoint);
1573
+ const baseUrlObj = new URL(this.baseUrl);
1574
+ if (endpointUrl.origin !== baseUrlObj.origin) {
1575
+ throw new Error("Endpoint must use the configured baseUrl");
1576
+ }
1577
+ }
1568
1578
  const url = new URL(endpoint, this.baseUrl);
1569
1579
  const response = await fetch(url.toString(), init);
1570
1580
  if (!response.ok) {
1571
1581
  throw new Error(`Failed to request ${url.toString()}: ${response.statusText}`);
1572
1582
  }
1573
- return await response.json();
1583
+ const data = await response.json();
1584
+ if (schema) {
1585
+ return schema.parse(data);
1586
+ }
1587
+ return data;
1574
1588
  }
1575
- async requestAuthenticated(endpoint, init) {
1589
+ async requestAuthenticated(endpoint, init, schema) {
1576
1590
  if (!this.apiKey) {
1577
1591
  throw new Error("API key is not set");
1578
1592
  }
1579
- return this.request(endpoint, {
1580
- ...init,
1581
- headers: {
1582
- ...init?.headers,
1583
- Authorization: `Bearer ${this.apiKey}`
1584
- // Override
1585
- }
1586
- });
1593
+ return this.request(
1594
+ endpoint,
1595
+ {
1596
+ ...init,
1597
+ headers: {
1598
+ ...init?.headers,
1599
+ Authorization: `Bearer ${this.apiKey}`
1600
+ }
1601
+ },
1602
+ schema
1603
+ );
1587
1604
  }
1588
1605
  async requestBlob(endpoint, init) {
1606
+ if (endpoint.startsWith("http://") || endpoint.startsWith("https://")) {
1607
+ const endpointUrl = new URL(endpoint);
1608
+ const baseUrlObj = new URL(this.baseUrl);
1609
+ if (endpointUrl.origin !== baseUrlObj.origin) {
1610
+ throw new Error("Endpoint must use the configured baseUrl");
1611
+ }
1612
+ }
1589
1613
  const url = new URL(endpoint, this.baseUrl);
1590
1614
  const response = await fetch(url.toString(), init);
1591
1615
  if (!response.ok) {