@zilfu/sdk 0.1.0 → 0.1.2

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.js CHANGED
@@ -821,7 +821,7 @@ var HeyApiRegistry = class {
821
821
  get(key) {
822
822
  const instance = this.instances.get(key ?? this.defaultKey);
823
823
  if (!instance) {
824
- throw new Error(`No SDK client found. Create one with "new ZilfuClient()" to fix this error.`);
824
+ throw new Error(`No SDK client found. Create one with "new ZilfuApi()" to fix this error.`);
825
825
  }
826
826
  return instance;
827
827
  }
@@ -830,18 +830,6 @@ var HeyApiRegistry = class {
830
830
  }
831
831
  };
832
832
  var Accounts = class extends HeyApiClient {
833
- /**
834
- * Disconnect multiple accounts
835
- *
836
- * Removes several social account connections in a single request and dispatches a webhook event for each.
837
- */
838
- deleteMany(options) {
839
- return (options.client ?? this.client).delete({
840
- security: [{ scheme: "bearer", type: "http" }],
841
- url: "/spaces/{space}/accounts",
842
- ...options
843
- });
844
- }
845
833
  /**
846
834
  * List accounts
847
835
  *
@@ -881,7 +869,7 @@ var Accounts = class extends HeyApiClient {
881
869
  /**
882
870
  * Disconnect an account
883
871
  *
884
- * Removes the social account connection and dispatches a webhook event.
872
+ * Removes the given account and every other account on the same platform within the space, dispatching an AccountDisconnected webhook for each.
885
873
  */
886
874
  delete(options) {
887
875
  return (options.client ?? this.client).delete({
@@ -891,7 +879,7 @@ var Accounts = class extends HeyApiClient {
891
879
  });
892
880
  }
893
881
  };
894
- var Tokens = class extends HeyApiClient {
882
+ var ApiTokens = class extends HeyApiClient {
895
883
  /**
896
884
  * Create an API token
897
885
  *
@@ -921,7 +909,7 @@ var Tokens = class extends HeyApiClient {
921
909
  });
922
910
  }
923
911
  };
924
- var BioBlocks = class extends HeyApiClient {
912
+ var Blocks = class extends HeyApiClient {
925
913
  list(options) {
926
914
  return (options.client ?? this.client).get({
927
915
  security: [{ scheme: "bearer", type: "http" }],
@@ -1012,6 +1000,19 @@ var Bio = class extends HeyApiClient {
1012
1000
  }
1013
1001
  });
1014
1002
  }
1003
+ _blocks;
1004
+ get blocks() {
1005
+ return this._blocks ??= new Blocks({ client: this.client });
1006
+ }
1007
+ };
1008
+ var Health = class extends HeyApiClient {
1009
+ check(options) {
1010
+ return (options?.client ?? this.client).get({
1011
+ security: [{ scheme: "bearer", type: "http" }],
1012
+ url: "/health",
1013
+ ...options
1014
+ });
1015
+ }
1015
1016
  };
1016
1017
  var Media = class extends HeyApiClient {
1017
1018
  /**
@@ -1330,28 +1331,28 @@ var Webhooks = class extends HeyApiClient {
1330
1331
  });
1331
1332
  }
1332
1333
  };
1333
- var ZilfuClient = class _ZilfuClient extends HeyApiClient {
1334
+ var ZilfuApi = class _ZilfuApi extends HeyApiClient {
1334
1335
  static __registry = new HeyApiRegistry();
1335
1336
  constructor(args) {
1336
1337
  super(args);
1337
- _ZilfuClient.__registry.set(this, args?.key);
1338
+ _ZilfuApi.__registry.set(this, args?.key);
1338
1339
  }
1339
1340
  _accounts;
1340
1341
  get accounts() {
1341
1342
  return this._accounts ??= new Accounts({ client: this.client });
1342
1343
  }
1343
- _tokens;
1344
- get tokens() {
1345
- return this._tokens ??= new Tokens({ client: this.client });
1346
- }
1347
- _bioBlocks;
1348
- get bioBlocks() {
1349
- return this._bioBlocks ??= new BioBlocks({ client: this.client });
1344
+ _apiTokens;
1345
+ get apiTokens() {
1346
+ return this._apiTokens ??= new ApiTokens({ client: this.client });
1350
1347
  }
1351
1348
  _bio;
1352
1349
  get bio() {
1353
1350
  return this._bio ??= new Bio({ client: this.client });
1354
1351
  }
1352
+ _health;
1353
+ get health() {
1354
+ return this._health ??= new Health({ client: this.client });
1355
+ }
1355
1356
  _media;
1356
1357
  get media() {
1357
1358
  return this._media ??= new Media({ client: this.client });
@@ -1386,17 +1387,67 @@ var ZilfuClient = class _ZilfuClient extends HeyApiClient {
1386
1387
  }
1387
1388
  };
1388
1389
 
1390
+ // src/errors.ts
1391
+ var ZilfuApiError = class extends Error {
1392
+ status;
1393
+ statusText;
1394
+ url;
1395
+ body;
1396
+ errors;
1397
+ constructor(init) {
1398
+ const message = extractMessage(init);
1399
+ super(message);
1400
+ this.name = "ZilfuApiError";
1401
+ this.status = init.status;
1402
+ this.statusText = init.statusText;
1403
+ this.url = init.url;
1404
+ this.body = init.body;
1405
+ this.errors = extractValidationErrors(init.body);
1406
+ }
1407
+ };
1408
+ function extractMessage(init) {
1409
+ const body = init.body;
1410
+ if (body && typeof body === "object" && "message" in body) {
1411
+ const m = body.message;
1412
+ if (typeof m === "string" && m.length > 0) {
1413
+ return m;
1414
+ }
1415
+ }
1416
+ return `Zilfu API ${init.status}${init.statusText ? ` ${init.statusText}` : ""}`;
1417
+ }
1418
+ function extractValidationErrors(body) {
1419
+ if (!body || typeof body !== "object" || !("errors" in body)) {
1420
+ return void 0;
1421
+ }
1422
+ const errors = body.errors;
1423
+ if (!errors || typeof errors !== "object") {
1424
+ return void 0;
1425
+ }
1426
+ return errors;
1427
+ }
1428
+
1389
1429
  // src/client.ts
1390
- function createZilfuClient(options) {
1391
- const { baseUrl, token, fetch: fetchImpl } = options;
1392
- client.setConfig({
1393
- baseUrl,
1394
- auth: token,
1395
- ...fetchImpl ? { fetch: fetchImpl } : {}
1430
+ function createZilfuClient(opts) {
1431
+ const client2 = createClient(
1432
+ createConfig({
1433
+ baseUrl: opts.baseUrl ?? "https://zilfu.app/api",
1434
+ fetch: opts.fetch,
1435
+ headers: { accept: "application/json", ...opts.headers },
1436
+ auth: opts.token,
1437
+ throwOnError: true
1438
+ })
1439
+ );
1440
+ client2.interceptors.error.use((error, response) => {
1441
+ return new ZilfuApiError({
1442
+ status: response?.status ?? 0,
1443
+ statusText: response?.statusText,
1444
+ url: response?.url,
1445
+ body: error
1446
+ });
1396
1447
  });
1397
- return new ZilfuClient();
1448
+ return new ZilfuApi({ client: client2 });
1398
1449
  }
1399
1450
 
1400
- export { Accounts, Bio, BioBlocks, Clusters, Media, Posts, Queue, Slots, Spaces, Subscription, Tokens, Webhooks, ZilfuClient, client, createZilfuClient };
1451
+ export { ZilfuApiError, createZilfuClient };
1401
1452
  //# sourceMappingURL=index.js.map
1402
1453
  //# sourceMappingURL=index.js.map