@zernio/node 0.2.783 → 0.2.785

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.mjs CHANGED
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5
5
  // package.json
6
6
  var package_default = {
7
7
  name: "@zernio/node",
8
- version: "0.2.783",
8
+ version: "0.2.785",
9
9
  description: "The official Node.js library for the Zernio API",
10
10
  main: "dist/index.js",
11
11
  module: "dist/index.mjs",
@@ -4725,12 +4725,17 @@ var downloadTikTokVideo = (options) => {
4725
4725
 
4726
4726
  // src/errors.ts
4727
4727
  var ZernioApiError = class _ZernioApiError extends Error {
4728
- constructor(message, statusCode, code, details) {
4728
+ constructor(message, statusCode, code, details, body) {
4729
4729
  super(message);
4730
4730
  this.name = "ZernioApiError";
4731
4731
  this.statusCode = statusCode;
4732
4732
  this.code = code;
4733
4733
  this.details = details;
4734
+ this.type = body?.type;
4735
+ this.param = body?.param;
4736
+ this.platform = body?.platform;
4737
+ this.platformError = body?.platformError;
4738
+ this.body = body;
4734
4739
  if (Error.captureStackTrace) {
4735
4740
  Error.captureStackTrace(this, _ZernioApiError);
4736
4741
  }
@@ -4774,8 +4779,8 @@ var ZernioApiError = class _ZernioApiError extends Error {
4774
4779
  };
4775
4780
  var LateApiError = ZernioApiError;
4776
4781
  var RateLimitError = class extends ZernioApiError {
4777
- constructor(message, limit, remaining, resetAt) {
4778
- super(message, 429, "rate_limit_exceeded");
4782
+ constructor(message, limit, remaining, resetAt, body) {
4783
+ super(message, 429, body?.code ?? "rate_limit_exceeded", body?.details, body);
4779
4784
  this.name = "RateLimitError";
4780
4785
  this.limit = limit;
4781
4786
  this.remaining = remaining;
@@ -4790,8 +4795,8 @@ var RateLimitError = class extends ZernioApiError {
4790
4795
  }
4791
4796
  };
4792
4797
  var ValidationError = class extends ZernioApiError {
4793
- constructor(message, fields) {
4794
- super(message, 400, "validation_error", { fields });
4798
+ constructor(message, fields, body) {
4799
+ super(message, 400, body?.code ?? "validation_error", body?.details ?? { fields }, body);
4795
4800
  this.name = "ValidationError";
4796
4801
  this.fields = fields;
4797
4802
  }
@@ -4808,13 +4813,14 @@ function parseApiError(response, body) {
4808
4813
  message,
4809
4814
  limit ? parseInt(limit, 10) : void 0,
4810
4815
  remaining ? parseInt(remaining, 10) : void 0,
4811
- reset ? new Date(parseInt(reset, 10) * 1e3) : void 0
4816
+ reset ? new Date(parseInt(reset, 10) * 1e3) : void 0,
4817
+ body
4812
4818
  );
4813
4819
  }
4814
4820
  if (response.status === 400 && details?.fields) {
4815
- return new ValidationError(message, details.fields);
4821
+ return new ValidationError(message, details.fields, body);
4816
4822
  }
4817
- return new ZernioApiError(message, response.status, code, details);
4823
+ return new ZernioApiError(message, response.status, code, details, body);
4818
4824
  }
4819
4825
 
4820
4826
  // src/client.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zernio/node",
3
- "version": "0.2.783",
3
+ "version": "0.2.785",
4
4
  "description": "The official Node.js library for the Zernio API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/errors.ts CHANGED
@@ -1,22 +1,57 @@
1
1
  /**
2
2
  * Base error class for Zernio API errors
3
3
  */
4
+ /**
5
+ * The canonical error envelope the API returns. Everything but `error` is
6
+ * optional, and every field is surfaced on ZernioApiError: dropping any of them
7
+ * leaves callers unable to tell apart failures the API distinguishes. For a
8
+ * Meta pass-through in particular, `platformError.subcode` is the only thing
9
+ * that separates a closed messaging window from a blocked recipient, since both
10
+ * arrive as code `platform_api_error`.
11
+ */
12
+ export interface ZernioErrorBody {
13
+ error?: string;
14
+ message?: string;
15
+ type?: string;
16
+ code?: string;
17
+ param?: string;
18
+ platform?: string;
19
+ platformError?: Record<string, unknown>;
20
+ details?: Record<string, unknown>;
21
+ }
22
+
4
23
  export class ZernioApiError extends Error {
5
24
  public readonly statusCode: number;
6
25
  public readonly code?: string;
7
26
  public readonly details?: Record<string, unknown>;
27
+ /** Error class, e.g. invalid_request_error, platform_error, rate_limit_error. */
28
+ public readonly type?: string;
29
+ /** The request field that caused the error, when the API names one. */
30
+ public readonly param?: string;
31
+ /** Upstream platform, present when type is platform_error. */
32
+ public readonly platform?: string;
33
+ /** The upstream platform's own payload, verbatim (Meta: code, subcode, fbtrace_id). */
34
+ public readonly platformError?: Record<string, unknown>;
35
+ /** The parsed response body exactly as the API sent it, for anything not modelled above. */
36
+ public readonly body?: ZernioErrorBody;
8
37
 
9
38
  constructor(
10
39
  message: string,
11
40
  statusCode: number,
12
41
  code?: string,
13
- details?: Record<string, unknown>
42
+ details?: Record<string, unknown>,
43
+ body?: ZernioErrorBody
14
44
  ) {
15
45
  super(message);
16
46
  this.name = 'ZernioApiError';
17
47
  this.statusCode = statusCode;
18
48
  this.code = code;
19
49
  this.details = details;
50
+ this.type = body?.type;
51
+ this.param = body?.param;
52
+ this.platform = body?.platform;
53
+ this.platformError = body?.platformError;
54
+ this.body = body;
20
55
 
21
56
  // Maintains proper stack trace for where error was thrown
22
57
  if (Error.captureStackTrace) {
@@ -82,9 +117,12 @@ export class RateLimitError extends ZernioApiError {
82
117
  message: string,
83
118
  limit?: number,
84
119
  remaining?: number,
85
- resetAt?: Date
120
+ resetAt?: Date,
121
+ body?: ZernioErrorBody
86
122
  ) {
87
- super(message, 429, 'rate_limit_exceeded');
123
+ // The envelope's own code wins when the API sent one: a Google Ads quota
124
+ // 429 and a Zernio rate limit are different failures.
125
+ super(message, 429, body?.code ?? 'rate_limit_exceeded', body?.details, body);
88
126
  this.name = 'RateLimitError';
89
127
  this.limit = limit;
90
128
  this.remaining = remaining;
@@ -106,8 +144,8 @@ export class RateLimitError extends ZernioApiError {
106
144
  export class ValidationError extends ZernioApiError {
107
145
  public readonly fields?: Record<string, string[]>;
108
146
 
109
- constructor(message: string, fields?: Record<string, string[]>) {
110
- super(message, 400, 'validation_error', { fields });
147
+ constructor(message: string, fields?: Record<string, string[]>, body?: ZernioErrorBody) {
148
+ super(message, 400, body?.code ?? 'validation_error', body?.details ?? { fields }, body);
111
149
  this.name = 'ValidationError';
112
150
  this.fields = fields;
113
151
  }
@@ -118,7 +156,7 @@ export class ValidationError extends ZernioApiError {
118
156
  */
119
157
  export function parseApiError(
120
158
  response: Response,
121
- body?: { error?: string; message?: string; code?: string; details?: Record<string, unknown> }
159
+ body?: ZernioErrorBody
122
160
  ): ZernioApiError {
123
161
  const message = body?.error || body?.message || response.statusText || 'Unknown error';
124
162
  const code = body?.code;
@@ -134,14 +172,15 @@ export function parseApiError(
134
172
  message,
135
173
  limit ? parseInt(limit, 10) : undefined,
136
174
  remaining ? parseInt(remaining, 10) : undefined,
137
- reset ? new Date(parseInt(reset, 10) * 1000) : undefined
175
+ reset ? new Date(parseInt(reset, 10) * 1000) : undefined,
176
+ body
138
177
  );
139
178
  }
140
179
 
141
180
  // Handle validation errors
142
181
  if (response.status === 400 && details?.fields) {
143
- return new ValidationError(message, details.fields as Record<string, string[]>);
182
+ return new ValidationError(message, details.fields as Record<string, string[]>, body);
144
183
  }
145
184
 
146
- return new ZernioApiError(message, response.status, code, details);
185
+ return new ZernioApiError(message, response.status, code, details, body);
147
186
  }
@@ -3925,10 +3925,28 @@ export type ErrorResponse = {
3925
3925
  [key: string]: unknown;
3926
3926
  };
3927
3927
  /**
3928
- * Additional structured context (e.g. field-level validation errors), for example `privateReplyConsumed` on the private-reply endpoint's 400 when the comment's single reply is already spent.
3928
+ * Additional structured context (e.g. field-level validation errors), for example
3929
+ * `privateReplyConsumed` on the private-reply endpoint's 400 when the comment's
3930
+ * single reply is already spent.
3931
+ *
3932
+ * On a Google Ads 429 it carries `quotaExhausted: true`, which marks the failure as
3933
+ * Google's own ads quota rather than a Zernio rate limit, so you can keep calling
3934
+ * other platforms instead of backing off everywhere. When Google names the scope it
3935
+ * also carries `quotaScope`: `DEVELOPER` means the shared developer-token budget
3936
+ * (every Google account is affected and there is nothing to change on your side),
3937
+ * `ACCOUNT` means your own ad account. A Meta 429 carries neither field.
3938
+ *
3929
3939
  */
3930
3940
  details?: {
3931
- [key: string]: unknown;
3941
+ /**
3942
+ * Google Ads 429 only. True when the upstream Google Ads quota is spent rather than a Zernio limit.
3943
+ */
3944
+ quotaExhausted?: boolean;
3945
+ /**
3946
+ * Google Ads 429 only, when Google names the scope. DEVELOPER is the shared developer-token budget; ACCOUNT is your ad account.
3947
+ */
3948
+ quotaScope?: 'DEVELOPER' | 'ACCOUNT';
3949
+ [key: string]: unknown | boolean | string;
3932
3950
  };
3933
3951
  };
3934
3952
 
@@ -3937,6 +3955,11 @@ export type ErrorResponse = {
3937
3955
  */
3938
3956
  export type type4 = 'invalid_request_error' | 'authentication_error' | 'permission_error' | 'not_found' | 'rate_limit_error' | 'platform_error' | 'api_error';
3939
3957
 
3958
+ /**
3959
+ * Google Ads 429 only, when Google names the scope. DEVELOPER is the shared developer-token budget; ACCOUNT is your ad account.
3960
+ */
3961
+ export type quotaScope = 'DEVELOPER' | 'ACCOUNT';
3962
+
3940
3963
  /**
3941
3964
  * A media item on a native (external/synced) post, as carried by post.external.* webhook payloads. Distinct from the richer MediaItem used for Zernio-authored posts: external items are always already-published and limited to image or video. Kept as a separate schema so the generated SDK model does not collide with MediaItem.
3942
3965
  *
@@ -24330,7 +24353,7 @@ export type ReplyToInboxReviewResponse = ({
24330
24353
  platform?: string;
24331
24354
  });
24332
24355
 
24333
- export type ReplyToInboxReviewError = ({
24356
+ export type ReplyToInboxReviewError = (ErrorResponse | {
24334
24357
  error?: string;
24335
24358
  } | unknown);
24336
24359