@billionsend/node 0.2.2 → 0.3.1

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
@@ -164,7 +164,7 @@ function sleep(ms, signal) {
164
164
  }
165
165
 
166
166
  // src/version.ts
167
- var VERSION = "0.2.2";
167
+ var VERSION = "0.3.1";
168
168
 
169
169
  // src/core.ts
170
170
  var DEFAULT_BASE_URL = "https://api.billionsend.com";
@@ -326,7 +326,7 @@ var Core = class {
326
326
  );
327
327
  }
328
328
  const keyed = headers["idempotency-key"] !== void 0;
329
- const safeToRepeat = IDEMPOTENT_METHODS.has(method) || keyed;
329
+ const safeToRepeat = IDEMPOTENT_METHODS.has(method) && init.noRepeat !== true || keyed;
330
330
  const maxRetries = options.maxRetries ?? this.maxRetries;
331
331
  const timeoutMs = options.timeoutMs ?? this.timeoutMs;
332
332
  for (let attempt = 0; ; attempt++) {
@@ -458,6 +458,95 @@ function idempotent(options) {
458
458
  return { idempotent: true, idempotencyKey: options?.idempotencyKey, options };
459
459
  }
460
460
 
461
+ // src/resources/brand.ts
462
+ var KINDS = [
463
+ { type: "image/png", extension: "png" },
464
+ { type: "image/jpeg", extension: "jpg" },
465
+ { type: "image/webp", extension: "webp" }
466
+ ];
467
+ function sniff(head) {
468
+ const at = (offset, ...bytes) => bytes.every((byte, i) => head[offset + i] === byte);
469
+ if (at(0, 137, 80, 78, 71, 13, 10, 26, 10)) return KINDS[0];
470
+ if (at(0, 255, 216, 255)) return KINDS[1];
471
+ if (at(0, 82, 73, 70, 70) && at(8, 87, 69, 66, 80)) return KINDS[2];
472
+ return void 0;
473
+ }
474
+ async function logoForm(params) {
475
+ const { file, filename, contentType } = params;
476
+ let blob;
477
+ let named;
478
+ if (file instanceof Blob) {
479
+ blob = file;
480
+ if ("name" in file && typeof file.name === "string" && file.name !== "") named = file.name;
481
+ } else {
482
+ blob = new Blob([file]);
483
+ }
484
+ let type = contentType ?? blob.type;
485
+ let kind;
486
+ if (type === "" || named === void 0) {
487
+ kind = sniff(new Uint8Array(await blob.slice(0, 12).arrayBuffer()));
488
+ if (type === "") type = kind?.type ?? "";
489
+ }
490
+ const form = new FormData();
491
+ form.append(
492
+ "file",
493
+ type === blob.type ? blob : new Blob([blob], { type }),
494
+ filename ?? named ?? `logo.${kind?.extension ?? "png"}`
495
+ );
496
+ return form;
497
+ }
498
+ var BrandLogo = class extends Resource {
499
+ /**
500
+ * `PUT /brand/logo`: uploads the team's logo (PNG, JPEG or WebP, at most 2 MiB)
501
+ * as `multipart/form-data`. An upload is not repeated after a 5xx or a dropped
502
+ * connection (a 429 is).
503
+ */
504
+ async upload(params, options) {
505
+ return this.core.request("put", "/brand/logo", {
506
+ form: await logoForm(params),
507
+ noRepeat: true,
508
+ options
509
+ });
510
+ }
511
+ /** `DELETE /brand/logo` */
512
+ delete(options) {
513
+ return this.core.request("delete", "/brand/logo", { options });
514
+ }
515
+ };
516
+ var Brand = class extends Resource {
517
+ logo = new BrandLogo(this.core);
518
+ /** `GET /brand` */
519
+ get(options) {
520
+ return this.core.request("get", "/brand", { options });
521
+ }
522
+ /** `PATCH /brand`: fields not sent keep their value. */
523
+ update(payload, options) {
524
+ return this.core.request("patch", "/brand", { body: payload, options });
525
+ }
526
+ };
527
+ var DomainUnsubscribePageLogo = class extends Resource {
528
+ /**
529
+ * `PUT /domains/{id}/unsubscribe-page/logo`: uploads the domain's logo (PNG,
530
+ * JPEG or WebP, at most 2 MiB) as `multipart/form-data`. An upload is not
531
+ * repeated after a 5xx or a dropped connection (a 429 is).
532
+ */
533
+ async upload(id, params, options) {
534
+ return this.core.request("put", "/domains/{id}/unsubscribe-page/logo", {
535
+ path: { id },
536
+ form: await logoForm(params),
537
+ noRepeat: true,
538
+ options
539
+ });
540
+ }
541
+ /** `DELETE /domains/{id}/unsubscribe-page/logo` */
542
+ delete(id, options) {
543
+ return this.core.request("delete", "/domains/{id}/unsubscribe-page/logo", { path: { id }, options });
544
+ }
545
+ };
546
+ var DomainUnsubscribePage = class extends Resource {
547
+ logo = new DomainUnsubscribePageLogo(this.core);
548
+ };
549
+
461
550
  // src/resources/account.ts
462
551
  var DomainClaims = class extends Resource {
463
552
  /** `POST /domains/claim`: starts a claim on a domain another team already holds. */
@@ -475,6 +564,7 @@ var DomainClaims = class extends Resource {
475
564
  };
476
565
  var Domains = class extends Resource {
477
566
  claims = new DomainClaims(this.core);
567
+ unsubscribePage = new DomainUnsubscribePage(this.core);
478
568
  /** `POST /domains` */
479
569
  create(payload, options) {
480
570
  return this.core.request("post", "/domains", { body: payload, options });
@@ -1949,6 +2039,7 @@ var BillionSend = class {
1949
2039
  events;
1950
2040
  logs;
1951
2041
  oauthGrants;
2042
+ brand;
1952
2043
  #core;
1953
2044
  /**
1954
2045
  * @param apiKeyOrOptions An API key (`bs_...`), or options. Without a key the
@@ -1980,6 +2071,7 @@ var BillionSend = class {
1980
2071
  this.events = new Events(core);
1981
2072
  this.logs = new Logs(core);
1982
2073
  this.oauthGrants = new OauthGrants(core);
2074
+ this.brand = new Brand(core);
1983
2075
  }
1984
2076
  /** The API base URL this client calls. */
1985
2077
  get baseUrl() {