@formfeed/sdk 0.3.2 → 0.3.4

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/index.cjs CHANGED
@@ -78,6 +78,7 @@ var Formfeed = class {
78
78
  fetchImpl;
79
79
  maxRetries;
80
80
  timeoutMs;
81
+ extraHeaders;
81
82
  constructor(options) {
82
83
  if (!options.apiKey) throw new FormfeedError("invalid_request", "apiKey is required", 0);
83
84
  this.apiKey = options.apiKey;
@@ -85,6 +86,7 @@ var Formfeed = class {
85
86
  this.fetchImpl = options.fetch ?? globalThis.fetch;
86
87
  this.maxRetries = options.maxRetries ?? 3;
87
88
  this.timeoutMs = options.timeoutMs ?? 12e4;
89
+ this.extraHeaders = Object.fromEntries(Object.entries(options.headers ?? {}).map(([name, value]) => [name.toLowerCase(), value]));
88
90
  if (!this.fetchImpl) throw new FormfeedError("invalid_request", "fetch is not available; pass options.fetch", 0);
89
91
  }
90
92
  renders = {
@@ -352,11 +354,20 @@ var Formfeed = class {
352
354
  );
353
355
  }
354
356
  },
355
- schema: (idOrSlug, options = {}) => this.request("GET", `/templates/${encodeURIComponent(idOrSlug)}/schema`, void 0, options),
357
+ /**
358
+ * The JSON Schema of the template's data: stored, else inferred from the sample data. Of the
359
+ * published (else the latest) version, or of `version`: `published`, `latest`, a number or a
360
+ * channel name.
361
+ */
362
+ schema: (idOrSlug, options = {}) => {
363
+ const { version, ...rest } = options;
364
+ const query = version === void 0 ? "" : `?version=${encodeURIComponent(String(version))}`;
365
+ return this.request("GET", `/templates/${encodeURIComponent(idOrSlug)}/schema${query}`, void 0, rest);
366
+ },
356
367
  /**
357
368
  * Checks a version with data without rendering: syntax, header and footer, missing partials,
358
369
  * runtime errors and the data against the stored schema. Free. Without `data`, the version's
359
- * sample data is checked.
370
+ * sample data is checked. `version` takes a channel name too.
360
371
  */
361
372
  validate: (idOrSlug, input = {}, options = {}) => this.request("POST", `/templates/${encodeURIComponent(idOrSlug)}/validate`, input, options)
362
373
  };
@@ -395,7 +406,8 @@ var Formfeed = class {
395
406
  const headers = {
396
407
  authorization: `Bearer ${this.apiKey}`,
397
408
  accept: as === "bytes" ? "*/*" : "application/json",
398
- "user-agent": "formfeed-sdk-ts/0.3"
409
+ "user-agent": "formfeed-sdk-ts/0.3",
410
+ ...this.extraHeaders
399
411
  };
400
412
  const isForm = typeof FormData !== "undefined" && body instanceof FormData;
401
413
  if (body !== void 0 && !isForm) headers["content-type"] = "application/json";
package/index.js CHANGED
@@ -49,6 +49,7 @@ var Formfeed = class {
49
49
  fetchImpl;
50
50
  maxRetries;
51
51
  timeoutMs;
52
+ extraHeaders;
52
53
  constructor(options) {
53
54
  if (!options.apiKey) throw new FormfeedError("invalid_request", "apiKey is required", 0);
54
55
  this.apiKey = options.apiKey;
@@ -56,6 +57,7 @@ var Formfeed = class {
56
57
  this.fetchImpl = options.fetch ?? globalThis.fetch;
57
58
  this.maxRetries = options.maxRetries ?? 3;
58
59
  this.timeoutMs = options.timeoutMs ?? 12e4;
60
+ this.extraHeaders = Object.fromEntries(Object.entries(options.headers ?? {}).map(([name, value]) => [name.toLowerCase(), value]));
59
61
  if (!this.fetchImpl) throw new FormfeedError("invalid_request", "fetch is not available; pass options.fetch", 0);
60
62
  }
61
63
  renders = {
@@ -323,11 +325,20 @@ var Formfeed = class {
323
325
  );
324
326
  }
325
327
  },
326
- schema: (idOrSlug, options = {}) => this.request("GET", `/templates/${encodeURIComponent(idOrSlug)}/schema`, void 0, options),
328
+ /**
329
+ * The JSON Schema of the template's data: stored, else inferred from the sample data. Of the
330
+ * published (else the latest) version, or of `version`: `published`, `latest`, a number or a
331
+ * channel name.
332
+ */
333
+ schema: (idOrSlug, options = {}) => {
334
+ const { version, ...rest } = options;
335
+ const query = version === void 0 ? "" : `?version=${encodeURIComponent(String(version))}`;
336
+ return this.request("GET", `/templates/${encodeURIComponent(idOrSlug)}/schema${query}`, void 0, rest);
337
+ },
327
338
  /**
328
339
  * Checks a version with data without rendering: syntax, header and footer, missing partials,
329
340
  * runtime errors and the data against the stored schema. Free. Without `data`, the version's
330
- * sample data is checked.
341
+ * sample data is checked. `version` takes a channel name too.
331
342
  */
332
343
  validate: (idOrSlug, input = {}, options = {}) => this.request("POST", `/templates/${encodeURIComponent(idOrSlug)}/validate`, input, options)
333
344
  };
@@ -366,7 +377,8 @@ var Formfeed = class {
366
377
  const headers = {
367
378
  authorization: `Bearer ${this.apiKey}`,
368
379
  accept: as === "bytes" ? "*/*" : "application/json",
369
- "user-agent": "formfeed-sdk-ts/0.3"
380
+ "user-agent": "formfeed-sdk-ts/0.3",
381
+ ...this.extraHeaders
370
382
  };
371
383
  const isForm = typeof FormData !== "undefined" && body instanceof FormData;
372
384
  if (body !== void 0 && !isForm) headers["content-type"] = "application/json";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formfeed/sdk",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Formfeed API client: renders, templates, webhooks. No dependencies, Web APIs only.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/types/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Formfeed, FormfeedError } from './lib/client.cjs';
2
- export type { Template, TemplateCreate, TemplateFiles, TemplateKind, TemplateListOptions, TemplateValidation, TemplateVersion, TemplateVersionCreate, TemplateFile, OfficeTemplateKind, OfficeTemplateCreate, OfficeVersionCreate, OfficeFileUpload, ConvertOptions, VersionStatus, BatchRequest, Channel, ChannelList, ChannelMove, Brand, SharedPartial, SharedPartialPut, SharedPartialPutResult, Diagnostic, Engine, FileListOptions, FileUpload, FormfeedOptions, FormfeedTemplates, Job, LibraryFile, OutputFormat, PdfInfo, PdfOutputOptions, PdfPermission, PostProcessing, Problem, ProtectOptions, Region, Render, RenderListOptions, RenderRequest, RenderStatus, TemplateData, TypedRenderRequest, RequestOptions, SchemaChange, SchemaCheck, SchemaGuardOptions, Usage, WaitOptions, WatermarkOptions, WebhookEndpoint, WebhookEndpointCreate, WebhookEndpointUpdate, WebhookEnvironment, WebhookResend, ListenSession, ListenSessionOptions, RenderInput, } from './lib/client.cjs';
2
+ export type { Template, TemplateCreate, TemplateFiles, TemplateKind, TemplateListOptions, TemplateValidation, VersionRef, TemplateVersion, TemplateVersionCreate, TemplateFile, OfficeTemplateKind, OfficeTemplateCreate, OfficeVersionCreate, OfficeFileUpload, ConvertOptions, VersionStatus, BatchRequest, Channel, ChannelList, ChannelMove, Brand, SharedPartial, SharedPartialPut, SharedPartialPutResult, Diagnostic, Engine, FileListOptions, FileUpload, FormfeedOptions, FormfeedTemplates, Job, LibraryFile, OutputFormat, PdfInfo, PdfOutputOptions, PdfPermission, PostProcessing, Problem, ProtectOptions, Region, Render, RenderListOptions, RenderRequest, RenderStatus, TemplateData, TypedRenderRequest, RequestOptions, SchemaChange, SchemaCheck, SchemaGuardOptions, Usage, WaitOptions, WatermarkOptions, WebhookEndpoint, WebhookEndpointCreate, WebhookEndpointUpdate, WebhookEnvironment, WebhookResend, ListenSession, ListenSessionOptions, RenderInput, } from './lib/client.cjs';
3
3
  export { parseWebhookEvent, verifyWebhookSignature } from './lib/webhooks.cjs';
4
4
  export type { VerifyOptions } from './lib/webhooks.cjs';
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Formfeed, FormfeedError } from './lib/client.js';
2
- export type { Template, TemplateCreate, TemplateFiles, TemplateKind, TemplateListOptions, TemplateValidation, TemplateVersion, TemplateVersionCreate, TemplateFile, OfficeTemplateKind, OfficeTemplateCreate, OfficeVersionCreate, OfficeFileUpload, ConvertOptions, VersionStatus, BatchRequest, Channel, ChannelList, ChannelMove, Brand, SharedPartial, SharedPartialPut, SharedPartialPutResult, Diagnostic, Engine, FileListOptions, FileUpload, FormfeedOptions, FormfeedTemplates, Job, LibraryFile, OutputFormat, PdfInfo, PdfOutputOptions, PdfPermission, PostProcessing, Problem, ProtectOptions, Region, Render, RenderListOptions, RenderRequest, RenderStatus, TemplateData, TypedRenderRequest, RequestOptions, SchemaChange, SchemaCheck, SchemaGuardOptions, Usage, WaitOptions, WatermarkOptions, WebhookEndpoint, WebhookEndpointCreate, WebhookEndpointUpdate, WebhookEnvironment, WebhookResend, ListenSession, ListenSessionOptions, RenderInput, } from './lib/client.js';
2
+ export type { Template, TemplateCreate, TemplateFiles, TemplateKind, TemplateListOptions, TemplateValidation, VersionRef, TemplateVersion, TemplateVersionCreate, TemplateFile, OfficeTemplateKind, OfficeTemplateCreate, OfficeVersionCreate, OfficeFileUpload, ConvertOptions, VersionStatus, BatchRequest, Channel, ChannelList, ChannelMove, Brand, SharedPartial, SharedPartialPut, SharedPartialPutResult, Diagnostic, Engine, FileListOptions, FileUpload, FormfeedOptions, FormfeedTemplates, Job, LibraryFile, OutputFormat, PdfInfo, PdfOutputOptions, PdfPermission, PostProcessing, Problem, ProtectOptions, Region, Render, RenderListOptions, RenderRequest, RenderStatus, TemplateData, TypedRenderRequest, RequestOptions, SchemaChange, SchemaCheck, SchemaGuardOptions, Usage, WaitOptions, WatermarkOptions, WebhookEndpoint, WebhookEndpointCreate, WebhookEndpointUpdate, WebhookEnvironment, WebhookResend, ListenSession, ListenSessionOptions, RenderInput, } from './lib/client.js';
3
3
  export { parseWebhookEvent, verifyWebhookSignature } from './lib/webhooks.js';
4
4
  export type { VerifyOptions } from './lib/webhooks.js';
@@ -22,6 +22,12 @@ export interface FormfeedOptions {
22
22
  /** Retries on 429 and 503; 0 disables. */
23
23
  maxRetries?: number;
24
24
  timeoutMs?: number;
25
+ /**
26
+ * Headers sent with every request, after the SDK's own. The hosted MCP server uses it to act for
27
+ * a signed-in member: `apiKey` carries the OAuth access token and `X-Formfeed-Workspace` the
28
+ * workspace of the URL (spec 10 §3.1).
29
+ */
30
+ headers?: Record<string, string>;
25
31
  }
26
32
  export interface RenderRequest {
27
33
  template?: string;
@@ -391,6 +397,8 @@ export interface Template {
391
397
  created_at: string;
392
398
  updated_at: string;
393
399
  }
400
+ /** A version as reads name it: `published`, `latest`, a version number or a channel name (its main version). */
401
+ export type VersionRef = string | number;
394
402
  /** One finding of `templates.validate`. */
395
403
  export interface Diagnostic {
396
404
  severity: 'error' | 'warning' | 'info';
@@ -402,6 +410,10 @@ export interface Diagnostic {
402
410
  };
403
411
  /** Data errors only: where in the data, e.g. `data.invoice.lines[0].qty`. */
404
412
  path?: string;
413
+ /** Word and PowerPoint templates only: the file part the tag is in, e.g. `word/document.xml`. */
414
+ part?: string;
415
+ /** Word and PowerPoint templates only: the 1-based paragraph in `part`. */
416
+ paragraph?: number;
405
417
  }
406
418
  export interface TemplateValidation {
407
419
  /** `false` when at least one diagnostic is an error. */
@@ -606,6 +618,7 @@ export declare class Formfeed {
606
618
  private readonly fetchImpl;
607
619
  private readonly maxRetries;
608
620
  private readonly timeoutMs;
621
+ private readonly extraHeaders;
609
622
  constructor(options: FormfeedOptions);
610
623
  readonly renders: {
611
624
  /** Renders a template, HTML or URL. Sync by default; `mode: 'async'` returns a queued render. */
@@ -762,14 +775,21 @@ export declare class Formfeed {
762
775
  force?: boolean;
763
776
  }) => Promise<void>;
764
777
  };
765
- schema: (idOrSlug: string, options?: RequestOptions) => Promise<Record<string, unknown>>;
778
+ /**
779
+ * The JSON Schema of the template's data: stored, else inferred from the sample data. Of the
780
+ * published (else the latest) version, or of `version`: `published`, `latest`, a number or a
781
+ * channel name.
782
+ */
783
+ schema: (idOrSlug: string, options?: RequestOptions & {
784
+ version?: VersionRef;
785
+ }) => Promise<Record<string, unknown>>;
766
786
  /**
767
787
  * Checks a version with data without rendering: syntax, header and footer, missing partials,
768
788
  * runtime errors and the data against the stored schema. Free. Without `data`, the version's
769
- * sample data is checked.
789
+ * sample data is checked. `version` takes a channel name too.
770
790
  */
771
791
  validate: (idOrSlug: string, input?: {
772
- version?: "published" | "latest" | number;
792
+ version?: VersionRef;
773
793
  data?: Record<string, unknown>;
774
794
  }, options?: RequestOptions) => Promise<TemplateValidation>;
775
795
  };
@@ -22,6 +22,12 @@ export interface FormfeedOptions {
22
22
  /** Retries on 429 and 503; 0 disables. */
23
23
  maxRetries?: number;
24
24
  timeoutMs?: number;
25
+ /**
26
+ * Headers sent with every request, after the SDK's own. The hosted MCP server uses it to act for
27
+ * a signed-in member: `apiKey` carries the OAuth access token and `X-Formfeed-Workspace` the
28
+ * workspace of the URL (spec 10 §3.1).
29
+ */
30
+ headers?: Record<string, string>;
25
31
  }
26
32
  export interface RenderRequest {
27
33
  template?: string;
@@ -391,6 +397,8 @@ export interface Template {
391
397
  created_at: string;
392
398
  updated_at: string;
393
399
  }
400
+ /** A version as reads name it: `published`, `latest`, a version number or a channel name (its main version). */
401
+ export type VersionRef = string | number;
394
402
  /** One finding of `templates.validate`. */
395
403
  export interface Diagnostic {
396
404
  severity: 'error' | 'warning' | 'info';
@@ -402,6 +410,10 @@ export interface Diagnostic {
402
410
  };
403
411
  /** Data errors only: where in the data, e.g. `data.invoice.lines[0].qty`. */
404
412
  path?: string;
413
+ /** Word and PowerPoint templates only: the file part the tag is in, e.g. `word/document.xml`. */
414
+ part?: string;
415
+ /** Word and PowerPoint templates only: the 1-based paragraph in `part`. */
416
+ paragraph?: number;
405
417
  }
406
418
  export interface TemplateValidation {
407
419
  /** `false` when at least one diagnostic is an error. */
@@ -606,6 +618,7 @@ export declare class Formfeed {
606
618
  private readonly fetchImpl;
607
619
  private readonly maxRetries;
608
620
  private readonly timeoutMs;
621
+ private readonly extraHeaders;
609
622
  constructor(options: FormfeedOptions);
610
623
  readonly renders: {
611
624
  /** Renders a template, HTML or URL. Sync by default; `mode: 'async'` returns a queued render. */
@@ -762,14 +775,21 @@ export declare class Formfeed {
762
775
  force?: boolean;
763
776
  }) => Promise<void>;
764
777
  };
765
- schema: (idOrSlug: string, options?: RequestOptions) => Promise<Record<string, unknown>>;
778
+ /**
779
+ * The JSON Schema of the template's data: stored, else inferred from the sample data. Of the
780
+ * published (else the latest) version, or of `version`: `published`, `latest`, a number or a
781
+ * channel name.
782
+ */
783
+ schema: (idOrSlug: string, options?: RequestOptions & {
784
+ version?: VersionRef;
785
+ }) => Promise<Record<string, unknown>>;
766
786
  /**
767
787
  * Checks a version with data without rendering: syntax, header and footer, missing partials,
768
788
  * runtime errors and the data against the stored schema. Free. Without `data`, the version's
769
- * sample data is checked.
789
+ * sample data is checked. `version` takes a channel name too.
770
790
  */
771
791
  validate: (idOrSlug: string, input?: {
772
- version?: "published" | "latest" | number;
792
+ version?: VersionRef;
773
793
  data?: Record<string, unknown>;
774
794
  }, options?: RequestOptions) => Promise<TemplateValidation>;
775
795
  };