@giveitsmaller/sdk 0.2.2 → 0.4.0

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/errors.d.ts CHANGED
@@ -1,21 +1,78 @@
1
+ import type { AuthErrorResponse, BalanceExhaustedResponse, FeatureNotAvailableResponse, FeatureTierRestrictedResponse, TierRestrictionResponse, WorkflowExpiredResponse } from '@giveitsmaller/contracts/openapi';
1
2
  export declare class GislError extends Error {
2
3
  constructor(message: string);
3
4
  }
5
+ /**
6
+ * Optional structured fields carried alongside a typed API error. The
7
+ * localisation triple (`messageKey`, `locale`, `messageParams`) mirrors the
8
+ * `ErrorEnvelope` localisation contract from `compression_contracts`
9
+ * (ticket I26). `payload` carries the full typed response envelope for the
10
+ * structured error subclasses that have one.
11
+ */
12
+ export interface GislApiErrorOptions {
13
+ readonly messageKey?: string;
14
+ readonly locale?: string;
15
+ readonly messageParams?: Record<string, unknown>;
16
+ readonly payload?: unknown;
17
+ }
4
18
  export declare class GislApiError extends GislError {
5
19
  readonly statusCode: number;
6
20
  readonly errorMessage: string;
7
- constructor(statusCode: number, errorMessage: string);
21
+ readonly path?: string;
22
+ readonly details?: unknown;
23
+ readonly messageKey?: string;
24
+ readonly locale?: string;
25
+ readonly messageParams?: Record<string, unknown>;
26
+ readonly payload?: unknown;
27
+ constructor(statusCode: number, errorMessage: string, path?: string, details?: unknown, options?: GislApiErrorOptions);
28
+ }
29
+ /**
30
+ * Shape of a single validation detail entry. Mirrors the v2
31
+ * `ValidationErrorEnvelopeDetailsInner` contract: only `message` is required;
32
+ * `field` / `operation` / `option` are mutually-permissive identifiers (a
33
+ * given detail may carry one, two, or all three depending on whether the
34
+ * violation is single-field, per-option, or cross-field).
35
+ */
36
+ export interface GislValidationDetail {
37
+ readonly message: string;
38
+ readonly field?: string;
39
+ readonly operation?: string;
40
+ readonly option?: string;
41
+ readonly messageKey?: string;
42
+ readonly locale?: string;
43
+ readonly messageParams?: Record<string, unknown>;
8
44
  }
9
45
  export declare class GislValidationError extends GislApiError {
10
- readonly details: Array<{
11
- field: string;
12
- message: string;
13
- }>;
14
- constructor(statusCode: number, errorMessage: string, details: Array<{
15
- field: string;
16
- message: string;
17
- }>);
46
+ readonly details: GislValidationDetail[];
47
+ constructor(statusCode: number, errorMessage: string, details: GislValidationDetail[], path?: string, options?: GislApiErrorOptions);
48
+ }
49
+ export declare class GislBalanceExhaustedError extends GislApiError {
50
+ readonly payload: BalanceExhaustedResponse;
51
+ constructor(statusCode: number, errorMessage: string, payload: BalanceExhaustedResponse, path?: string, extra?: Omit<GislApiErrorOptions, 'payload'>);
52
+ }
53
+ export declare class GislTierRestrictedError extends GislApiError {
54
+ readonly payload: TierRestrictionResponse;
55
+ constructor(statusCode: number, errorMessage: string, payload: TierRestrictionResponse, path?: string, extra?: Omit<GislApiErrorOptions, 'payload'>);
56
+ }
57
+ export declare class GislFeatureTierRestrictedError extends GislApiError {
58
+ readonly payload: FeatureTierRestrictedResponse;
59
+ constructor(statusCode: number, errorMessage: string, payload: FeatureTierRestrictedResponse, path?: string, extra?: Omit<GislApiErrorOptions, 'payload'>);
60
+ }
61
+ export declare class GislFeatureNotAvailableError extends GislApiError {
62
+ readonly payload: FeatureNotAvailableResponse;
63
+ constructor(statusCode: number, errorMessage: string, payload: FeatureNotAvailableResponse, path?: string, extra?: Omit<GislApiErrorOptions, 'payload'>);
64
+ }
65
+ export declare class GislWorkflowExpiredError extends GislApiError {
66
+ readonly payload: WorkflowExpiredResponse;
67
+ constructor(statusCode: number, errorMessage: string, payload: WorkflowExpiredResponse, path?: string, extra?: Omit<GislApiErrorOptions, 'payload'>);
68
+ }
69
+ export declare class GislAuthError extends GislApiError {
70
+ readonly payload: AuthErrorResponse;
71
+ constructor(statusCode: number, errorMessage: string, payload: AuthErrorResponse, path?: string, extra?: Omit<GislApiErrorOptions, 'payload'>);
18
72
  }
19
73
  export declare class GislTimeoutError extends GislError {
20
74
  constructor(message: string);
21
75
  }
76
+ export declare class GislAbortError extends GislError {
77
+ constructor(message: string);
78
+ }
package/dist/errors.js CHANGED
@@ -7,19 +7,76 @@ export class GislError extends Error {
7
7
  export class GislApiError extends GislError {
8
8
  statusCode;
9
9
  errorMessage;
10
- constructor(statusCode, errorMessage) {
11
- super(`API error ${statusCode}: ${errorMessage}`);
10
+ path;
11
+ details;
12
+ messageKey;
13
+ locale;
14
+ messageParams;
15
+ payload;
16
+ constructor(statusCode, errorMessage, path, details, options) {
17
+ const prefix = path
18
+ ? `API error ${statusCode} at ${path}`
19
+ : `API error ${statusCode}`;
20
+ super(`${prefix}: ${errorMessage}`);
12
21
  this.name = 'GislApiError';
13
22
  this.statusCode = statusCode;
14
23
  this.errorMessage = errorMessage;
24
+ this.path = path;
25
+ this.details = details;
26
+ if (options) {
27
+ this.messageKey = options.messageKey;
28
+ this.locale = options.locale;
29
+ this.messageParams = options.messageParams;
30
+ this.payload = options.payload;
31
+ }
15
32
  }
16
33
  }
17
34
  export class GislValidationError extends GislApiError {
18
- details;
19
- constructor(statusCode, errorMessage, details) {
20
- super(statusCode, errorMessage);
35
+ constructor(statusCode, errorMessage, details, path, options) {
36
+ super(statusCode, errorMessage, path, details, options);
21
37
  this.name = 'GislValidationError';
22
- this.details = details;
38
+ }
39
+ }
40
+ // Shared constructor body for the structured-payload subclasses. Five of the
41
+ // six subclasses below differ only in their typed `payload` and `name` —
42
+ // factor the common construction here so each subclass remains a one-liner.
43
+ function buildOptionsWithPayload(payload, extra) {
44
+ return { ...extra, payload };
45
+ }
46
+ export class GislBalanceExhaustedError extends GislApiError {
47
+ constructor(statusCode, errorMessage, payload, path, extra) {
48
+ super(statusCode, errorMessage, path, undefined, buildOptionsWithPayload(payload, extra));
49
+ this.name = 'GislBalanceExhaustedError';
50
+ }
51
+ }
52
+ export class GislTierRestrictedError extends GislApiError {
53
+ constructor(statusCode, errorMessage, payload, path, extra) {
54
+ super(statusCode, errorMessage, path, undefined, buildOptionsWithPayload(payload, extra));
55
+ this.name = 'GislTierRestrictedError';
56
+ }
57
+ }
58
+ export class GislFeatureTierRestrictedError extends GislApiError {
59
+ constructor(statusCode, errorMessage, payload, path, extra) {
60
+ super(statusCode, errorMessage, path, undefined, buildOptionsWithPayload(payload, extra));
61
+ this.name = 'GislFeatureTierRestrictedError';
62
+ }
63
+ }
64
+ export class GislFeatureNotAvailableError extends GislApiError {
65
+ constructor(statusCode, errorMessage, payload, path, extra) {
66
+ super(statusCode, errorMessage, path, undefined, buildOptionsWithPayload(payload, extra));
67
+ this.name = 'GislFeatureNotAvailableError';
68
+ }
69
+ }
70
+ export class GislWorkflowExpiredError extends GislApiError {
71
+ constructor(statusCode, errorMessage, payload, path, extra) {
72
+ super(statusCode, errorMessage, path, undefined, buildOptionsWithPayload(payload, extra));
73
+ this.name = 'GislWorkflowExpiredError';
74
+ }
75
+ }
76
+ export class GislAuthError extends GislApiError {
77
+ constructor(statusCode, errorMessage, payload, path, extra) {
78
+ super(statusCode, errorMessage, path, undefined, buildOptionsWithPayload(payload, extra));
79
+ this.name = 'GislAuthError';
23
80
  }
24
81
  }
25
82
  export class GislTimeoutError extends GislError {
@@ -28,3 +85,9 @@ export class GislTimeoutError extends GislError {
28
85
  this.name = 'GislTimeoutError';
29
86
  }
30
87
  }
88
+ export class GislAbortError extends GislError {
89
+ constructor(message) {
90
+ super(message);
91
+ this.name = 'GislAbortError';
92
+ }
93
+ }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  export { GislClient, DEFAULT_MULTIPART_FIRST_CHUNK_SIZE } from './client.js';
2
2
  export { verifyWebhook } from './webhook.js';
3
3
  export { parseSseStream } from './sse.js';
4
- export type { GislClientConfig, GislSseEvent, UploadOptions, WaitOptions, WorkflowCreatePayload, OperationDef, FileJobPayload, SourceJobPayload, InputsJobPayload, JobDefinitionPayload, } from './types.js';
5
- export { fileJob, sourceJob, inputsJob } from './types.js';
6
- export { GislError, GislApiError, GislValidationError, GislTimeoutError, } from './errors.js';
7
- export type { UploadResponse, WorkflowCreateResponse, WorkflowStatusResponse, WorkflowDownloadResponse, MetadataResponse, OperationsSchemaResponse, RetryResponse, JobDownload, OperationDownload, WebhookPayload, JobResponse, OperationResponse, OperationResult, ExportConfig, } from '@giveitsmaller/contracts/openapi';
8
- export { WorkflowStatus, OperationType, SseEventType, CallbackEventType, OperationStatus, JobStatus, } from '@giveitsmaller/contracts/openapi';
4
+ export type { CreditsUsageOptions, GetSchemaOptions, GetSchemaResult, PreflightClipError, PreflightClipsResult, GislClientConfig, GislSseEvent, UploadOptions, WaitOptions, WorkflowCreatePayload, OperationDef, WorkflowSourcePayload, UploadSourcePayload, JobOutputSourcePayload, ExternalImportSourcePayload, ConnectionSourcePayload, JobInputV2Payload, JobDefinitionPayload, ExternalDestinationPayload, DeliveryPayload, DeliveryModePayload, DeliveryBundleFormatPayload, DeliverySelectionPayload, DeliverySelectionTypePayload, DeliveryOutputRefPayload, WorkflowProcessingPayload, ProcessingClassHintPayload, } from './types.js';
5
+ export { uploadSource, jobOutputSource, externalImportSource, connectionSource, } from './types.js';
6
+ export { GislError, GislApiError, GislValidationError, GislBalanceExhaustedError, GislTierRestrictedError, GislFeatureTierRestrictedError, GislFeatureNotAvailableError, GislWorkflowExpiredError, GislAuthError, GislTimeoutError, GislAbortError, } from './errors.js';
7
+ export type { GislApiErrorOptions } from './errors.js';
8
+ export type { AudioWatermarkDecodeRequest, AudioWatermarkDecodeResponse, ContactRequest, CreditsBalanceResponse, CreditsUsageResponse, CreditTransaction, ExternalImportCreatedResponse, ExternalImportRequest, LoginUserRequest, LoginUser200ResponseData, LoginUser200ResponseDataUser, WorkflowCancelResponse, WorkflowResumeResponse, WorkflowPausedDetail, WorkflowPausedDetailLinks, UploadResponse, UploadConstraintsApplied, UploadProbeResponse, UploadProbeMediaMetadata, MultipartInitiateRequestMetadataHint, WorkflowCreateResponse, WorkflowStatusResponse, WorkflowDownloadResponse, MetadataResponse, MetadataResponseDimensions, MetadataResponseExif, MetadataResponseExifGps, OperationsSchemaResponse, OperationSchemaDefinition, MimeGroupSchema, OptionSchema, PerValueAvailabilityEntry, RetryResponse, JobDownload, OperationDownload, WebhookPayload, WebhookOperationContext, JobResponse, OperationResponse, OperationResult, OperationResultMetrics, ExternalDestination, Delivery, DeliveryPlan, DeliveryPlanOutput, WorkflowProcessing, ProcessingPlan, ProcessingPlanJob, WorkflowEdge, WorkflowWarning, JobInputV2, WorkflowSource, UploadSource, JobOutputSource, ConnectionSource, ExternalImportToken, BalanceExhaustedResponse, BalanceExhaustedResponseAllOfLinks, TierRestrictionResponse, FeatureTierRestrictedResponse, FeatureNotAvailableResponse, FeatureViolation, WorkflowExpiredResponse, AuthErrorResponse, } from '@giveitsmaller/contracts/openapi';
9
+ export { AudioWatermarkDecodeRequestMethodHintEnum, AudioWatermarkDecodeResponseMethodEnum, OperationInputModel, ExternalImportRequestProviderHintEnum, ContactSubject, CreditTransactionSourceBucket, UploadProbeStatus, UploadProbeProcessingClass, WorkflowCancelBillingEffect, WorkflowPauseRequiredAction, WorkflowStatus, WarningType, WorkflowWarningSeverity, OperationType, SseEventType, CallbackEventType, OperationStatus, JobStatus, JobInputV2RoleEnum, AuthErrorType, TierRestrictionKind, BalanceExhaustedResponseRequiredActionEnum, ProcessingClassReason, DeliveryPlanReason, UserTier, ProcessingClass, } from '@giveitsmaller/contracts/openapi';
9
10
  export type { SseOperationProgressData, SseOperationCompletedData, SseOperationFailedData, SseJobCompletedData, SseJobFailedData, SseWorkflowTerminalData, } from '@giveitsmaller/contracts/openapi';
10
- export type { CompressImageOptions, CompressVideoOptions, CompressAudioOptions, CompressDocumentPdfOptions, CompressDocumentOfficeOptions, CompressDocumentOdfOptions, CompressDocumentEpubOptions, ThumbnailImageOptions, ThumbnailVideoOptions, ThumbnailDocumentOptions, ConvertImageOptions, ConvertVideoOptions, ConvertAudioOptions, ConvertDocumentPdfOptions, MergeImageOptions, MergeVideoOptions, MergeAudioOptions, MergeDocumentOptions, ArchiveOptions, } from '@giveitsmaller/contracts/operations';
11
+ export type { MultiOutputCompletion, PageIndexed, PositionIndexed, Unindexed, } from '@giveitsmaller/contracts/asyncapi';
12
+ import type { MultiOutputCompletion as _MultiOutputCompletion } from '@giveitsmaller/contracts/asyncapi';
13
+ export type OperationResultOutputEntry = _MultiOutputCompletion['outputs'][number];
14
+ export type { CompressImageOptions, CompressVideoOptions, CompressAudioOptions, CompressDocumentPdfOptions, CompressDocumentOfficeOptions, CompressDocumentOdfOptions, CompressDocumentEpubOptions, ThumbnailImageOptions, ThumbnailVideoOptions, ThumbnailDocumentOptions, ConvertImageOptions, ConvertVideoOptions, ConvertAudioOptions, ConvertDocumentPdfOptions, MergeImageOptions, MergeVideoOptions, MergeVideoPerInputOptions, MergeAudioOptions, MergeAudioPerInputOptions, ArchiveOptions, ImageWatermarkImageOptions, ImageWatermarkImageGifOptions, ImageWatermarkVideoOptions, TextWatermarkImageOptions, CustomLumaVideoOptions, AudioOverlayAudioOptions, AudioOverlayVideoOptions, AudioWatermarkAudioOptions, AudioWatermarkVideoOptions, } from '@giveitsmaller/contracts/operations';
15
+ export { ImageWatermarkImageAnchor, ImageWatermarkImageGifAnchor, ImageWatermarkVideoAnchor, TextWatermarkImageAnchor, TextWatermarkImageFontFamily, TextWatermarkImageWatermarkMode, AudioOverlayAudioMode, AudioOverlayVideoMode, AudioOverlayVideoNoAudioTrackBehaviour, AudioWatermarkAudioMethod, AudioWatermarkAudioRobustness, AudioWatermarkAudioDensity, AudioWatermarkVideoMethod, AudioWatermarkVideoRobustness, AudioWatermarkVideoDensity, } from '@giveitsmaller/contracts/operations';
16
+ export { archiveMetadata, audioOverlayMetadata, audioWatermarkMetadata, compressMetadata, convertMetadata, customLumaMetadata, imageWatermarkMetadata, mergeMetadata, textWatermarkMetadata, thumbnailMetadata, } from '@giveitsmaller/contracts/operations';
17
+ export type { OperationMetadata, AvailabilityValue, AvailabilityEntry, FeatureEntry, MimeGroupMetadata, OptionMetadata, ProcessingClassConstraints, } from '@giveitsmaller/contracts/operations';
package/dist/index.js CHANGED
@@ -2,7 +2,31 @@
2
2
  export { GislClient, DEFAULT_MULTIPART_FIRST_CHUNK_SIZE } from './client.js';
3
3
  export { verifyWebhook } from './webhook.js';
4
4
  export { parseSseStream } from './sse.js';
5
- export { fileJob, sourceJob, inputsJob } from './types.js';
5
+ export { uploadSource, jobOutputSource, externalImportSource, connectionSource, } from './types.js';
6
6
  // Errors
7
- export { GislError, GislApiError, GislValidationError, GislTimeoutError, } from './errors.js';
8
- export { WorkflowStatus, OperationType, SseEventType, CallbackEventType, OperationStatus, JobStatus, } from '@giveitsmaller/contracts/openapi';
7
+ export { GislError, GislApiError, GislValidationError, GislBalanceExhaustedError, GislTierRestrictedError, GislFeatureTierRestrictedError, GislFeatureNotAvailableError, GislWorkflowExpiredError, GislAuthError, GislTimeoutError, GislAbortError, } from './errors.js';
8
+ export { AudioWatermarkDecodeRequestMethodHintEnum, AudioWatermarkDecodeResponseMethodEnum,
9
+ // OperationInputModel — value-bearing enum (`single` | `multi`).
10
+ // Surfaced on OperationSchemaDefinition.inputModel so form-renderers
11
+ // can decide whether to render a single-file picker or a multi-file
12
+ // input list.
13
+ OperationInputModel, ExternalImportRequestProviderHintEnum, ContactSubject, CreditTransactionSourceBucket, UploadProbeStatus, UploadProbeProcessingClass, WorkflowCancelBillingEffect, WorkflowPauseRequiredAction, WorkflowStatus, WarningType, WorkflowWarningSeverity, OperationType, SseEventType, CallbackEventType, OperationStatus, JobStatus, JobInputV2RoleEnum,
14
+ // Error-payload discriminator enums — pair with the typed payload
15
+ // types above for narrowing inside `error instanceof Gisl<X>Error`
16
+ // branches.
17
+ AuthErrorType, TierRestrictionKind, BalanceExhaustedResponseRequiredActionEnum, ProcessingClassReason, DeliveryPlanReason,
18
+ // UserTier + ProcessingClass — value-bearing forms (typeof const +
19
+ // type alias). Sourced from openapi so consumers can do
20
+ // `Object.values(UserTier)` for tier dropdowns or
21
+ // `if (tier === UserTier.enterprise)` for narrowing typed error
22
+ // payloads. The operations metadata-types versions are pure type
23
+ // aliases (no runtime value); the openapi versions carry both the
24
+ // string-union type and a const map. Per audit follow-up.
25
+ UserTier, ProcessingClass, } from '@giveitsmaller/contracts/openapi';
26
+ export { ImageWatermarkImageAnchor, ImageWatermarkImageGifAnchor, ImageWatermarkVideoAnchor, TextWatermarkImageAnchor, TextWatermarkImageFontFamily, TextWatermarkImageWatermarkMode, AudioOverlayAudioMode, AudioOverlayVideoMode, AudioOverlayVideoNoAudioTrackBehaviour, AudioWatermarkAudioMethod, AudioWatermarkAudioRobustness, AudioWatermarkAudioDensity, AudioWatermarkVideoMethod, AudioWatermarkVideoRobustness, AudioWatermarkVideoDensity, } from '@giveitsmaller/contracts/operations';
27
+ // Per-operation metadata sidecars. Inspect `availability`,
28
+ // `required_tier`, per-value gating, mime-group availability and
29
+ // per-feature flags before submitting a workflow — the API will
30
+ // otherwise reject planned ops with `feature_not_available` (422,
31
+ // surfaces as `GislFeatureNotAvailableError`).
32
+ export { archiveMetadata, audioOverlayMetadata, audioWatermarkMetadata, compressMetadata, convertMetadata, customLumaMetadata, imageWatermarkMetadata, mergeMetadata, textWatermarkMetadata, thumbnailMetadata, } from '@giveitsmaller/contracts/operations';
package/dist/types.d.ts CHANGED
@@ -1,54 +1,144 @@
1
- import type { OperationType, CallbackEventType, SseEventType, SseOperationProgressData, SseOperationCompletedData, SseOperationFailedData, SseJobCompletedData, SseJobFailedData, SseWorkflowTerminalData } from '@giveitsmaller/contracts/openapi';
1
+ import type { OperationType, OperationsSchemaResponse, CallbackEventType, SseEventType, SseOperationProgressData, SseOperationCompletedData, SseOperationFailedData, SseJobCompletedData, SseJobFailedData, SseWorkflowTerminalData, MultipartInitiateRequestMetadataHint, UploadProbeResponse } from '@giveitsmaller/contracts/openapi';
2
+ import type { JobInputV2RoleEnum } from '@giveitsmaller/contracts/openapi';
2
3
  export interface GislClientConfig {
3
4
  baseUrl: string;
4
5
  apiKey?: string;
5
6
  headers?: Record<string, string>;
6
7
  timeout?: number;
8
+ /**
9
+ * Send credentials (cookies) on every fetch — required in browsers when
10
+ * authenticating via the session cookie issued by `POST /api/auth/login`
11
+ * (Symfony firewall). Default `false` — the SDK ships in API-key mode by
12
+ * default. Set to `true` for browser SPAs that drive the auth flow via
13
+ * `client.login()` / `client.logout()` so the session cookie persists
14
+ * across requests.
15
+ *
16
+ * Node session persistence (cookie-jar across processes) is out of scope —
17
+ * this flag only flips fetch's `credentials` option; cookie storage is the
18
+ * environment's responsibility.
19
+ */
20
+ useSessionCookie?: boolean;
7
21
  /** Threshold in bytes above which multipart upload is used (default: 10MB) */
8
22
  multipartThreshold?: number;
9
- /** Max concurrent chunk uploads for multipart (default: 4) */
23
+ /**
24
+ * Max concurrent chunk uploads for multipart (default: 4). Non-finite or
25
+ * fractional values are coerced via `Math.floor`; `NaN`/`Infinity` and
26
+ * non-positive values fall back to the default. Zero workers would produce
27
+ * a multipart-complete with an incomplete parts array (silent corruption),
28
+ * so the sanitiser snaps below-1 to default rather than to 1.
29
+ */
10
30
  multipartConcurrency?: number;
31
+ /**
32
+ * Max total attempts per multipart S3 PUT, including the first try
33
+ * (default: 3 — one initial + two retries). 0 or 1 disables retry.
34
+ * Non-finite or fractional values are coerced via `Math.floor` and
35
+ * floored at 1; `NaN`/`Infinity` fall back to the default.
36
+ * Retries fire on 5xx/429 responses and on network TypeError; 4xx (other
37
+ * than 429) and abort signals fail fast.
38
+ */
39
+ multipartMaxAttempts?: number;
40
+ /**
41
+ * Base milliseconds for full-jitter exponential backoff between multipart
42
+ * retry attempts (default: 500). Each retry's delay is `random(0, base * 2^n)`
43
+ * where n is the zero-indexed retry number. `0` opts out of backoff (retries
44
+ * fire immediately) — useful for tests; not recommended for production where
45
+ * jitter is the only defence against thundering-herd retry storms against
46
+ * shared-throttling sources like S3. `NaN`/`Infinity` fall back to the default.
47
+ */
48
+ multipartRetryBaseMs?: number;
11
49
  }
12
50
  export interface OperationDef {
13
51
  type: OperationType;
14
52
  options?: Record<string, unknown>;
15
53
  }
16
- /** Job sourced from an uploaded file */
17
- export interface FileJobPayload {
18
- ref: string;
54
+ export interface UploadSourcePayload {
55
+ type: 'upload';
19
56
  file_id: string;
20
- operations: OperationDef[];
21
57
  }
22
- /** Job sourced from a single upstream job's output */
23
- export interface SourceJobPayload {
24
- ref: string;
25
- source: {
26
- ref: string;
27
- operation?: string;
28
- };
29
- operations: OperationDef[];
58
+ export interface JobOutputSourcePayload {
59
+ type: 'job_output';
60
+ from: string;
61
+ operation?: string;
30
62
  }
31
- /** Job sourced from multiple upstream jobs (merge/archive) */
32
- export interface InputsJobPayload {
33
- ref: string;
34
- inputs: Array<{
35
- ref: string;
36
- operation?: string;
37
- per_input_options?: Record<string, unknown>;
38
- }>;
63
+ export interface ExternalImportSourcePayload {
64
+ type: 'external_import';
65
+ external_source_id: string;
66
+ }
67
+ export interface ConnectionSourcePayload {
68
+ type: 'connection';
69
+ connection_id: string;
70
+ path: string;
71
+ }
72
+ export type WorkflowSourcePayload = UploadSourcePayload | JobOutputSourcePayload | ExternalImportSourcePayload | ConnectionSourcePayload;
73
+ export declare function uploadSource(fileId: string): UploadSourcePayload;
74
+ export declare function jobOutputSource(from: string, operation?: string): JobOutputSourcePayload;
75
+ export declare function externalImportSource(externalSourceId: string): ExternalImportSourcePayload;
76
+ export declare function connectionSource(connectionId: string, path: string): ConnectionSourcePayload;
77
+ export interface JobInputV2Payload {
78
+ source: WorkflowSourcePayload;
79
+ role?: JobInputV2RoleEnum;
80
+ per_input_options?: Record<string, unknown>;
81
+ }
82
+ export interface JobDefinitionPayload {
83
+ /**
84
+ * Optional local identifier within the workflow. Server auto-generates
85
+ * `^job_\d+$` when omitted; the SDK MUST NOT auto-generate. Required
86
+ * when this job is referenced by another job's `JobOutputSource.from`,
87
+ * `workflow_edges`, or `delivery.selection.explicit.refs[]`.
88
+ */
89
+ id?: string;
90
+ /** Single-input source. Mutually exclusive with `inputs[]` (server enforces). */
91
+ source?: WorkflowSourcePayload;
92
+ /** Multi-input list for merge / archive / image_watermark / custom_luma / audio_overlay. */
93
+ inputs?: JobInputV2Payload[];
39
94
  operations: OperationDef[];
95
+ /** Per-job hide-intermediates promotion flag per ADR-0003. */
96
+ deliver?: boolean;
97
+ /**
98
+ * Per-job opt-out of the "compress required in every chain" gate.
99
+ * When `true`, the server accepts a chain that doesn't terminate in a
100
+ * `compress` operation — required for chains that observe multi-output
101
+ * fan-out (e.g. convert PDF -> N images per ADR-0009 §D2) without
102
+ * collapsing the N outputs through a trailing chained compress.
103
+ *
104
+ * Accepted by the API at `compression/src/Jobs/.../JobDefinition.php`
105
+ * (`skipCompression`) and validated against the chain-ordering rule at
106
+ * `Job::validateChainOrdering`. Currently undocumented in
107
+ * `contracts/openapi/api.yaml` JobDefinition schema — spec follow-up
108
+ * pending; the SDK exposes the field to unblock e2e A8-FLIP.
109
+ */
110
+ skip_compression?: boolean;
40
111
  }
41
- export type JobDefinitionPayload = FileJobPayload | SourceJobPayload | InputsJobPayload;
42
- export declare function fileJob(ref: string, fileId: string, operations: OperationDef[]): FileJobPayload;
43
- export declare function sourceJob(ref: string, source: {
44
- ref: string;
45
- operation?: string;
46
- }, operations: OperationDef[]): SourceJobPayload;
47
- export declare function inputsJob(ref: string, inputs: Array<{
112
+ export type ExternalDestinationPayload = {
113
+ type: 'connection';
114
+ connection_id: string;
115
+ path: string;
116
+ } | {
117
+ type: 'external_import';
118
+ external_source_id: string;
119
+ };
120
+ export type DeliveryModePayload = 'individual' | 'bundle' | 'both';
121
+ export type DeliveryBundleFormatPayload = 'zip' | 'tar_gz';
122
+ export type DeliverySelectionTypePayload = 'terminal' | 'all_outputs' | 'explicit';
123
+ export interface DeliveryOutputRefPayload {
48
124
  ref: string;
49
125
  operation?: string;
50
- per_input_options?: Record<string, unknown>;
51
- }>, operations: OperationDef[]): InputsJobPayload;
126
+ }
127
+ export interface DeliverySelectionPayload {
128
+ type: DeliverySelectionTypePayload;
129
+ refs?: DeliveryOutputRefPayload[];
130
+ }
131
+ export interface DeliveryPayload {
132
+ mode?: DeliveryModePayload;
133
+ bundle_format?: DeliveryBundleFormatPayload;
134
+ bundle_filename?: string;
135
+ include_metadata?: boolean;
136
+ selection?: DeliverySelectionPayload;
137
+ }
138
+ export type ProcessingClassHintPayload = 'auto' | 'short_form_only' | 'long_form_allowed' | 'long_form_preferred';
139
+ export interface WorkflowProcessingPayload {
140
+ class_hint?: ProcessingClassHintPayload;
141
+ }
52
142
  export interface WorkflowCreatePayload {
53
143
  jobs: JobDefinitionPayload[];
54
144
  workflow_edges?: Array<{
@@ -57,12 +147,87 @@ export interface WorkflowCreatePayload {
57
147
  }>;
58
148
  callback_url?: string;
59
149
  callback_events?: CallbackEventType[];
60
- export?: {
61
- service: 's3';
62
- bucket: string;
63
- key_prefix?: string;
64
- role_arn: string;
65
- };
150
+ export?: ExternalDestinationPayload;
151
+ delivery?: DeliveryPayload;
152
+ processing?: WorkflowProcessingPayload;
153
+ }
154
+ /**
155
+ * Single source of truth for WorkflowCreatePayload's top-level wire keys.
156
+ * Read by `contract-drift-fields.test.ts` to cross-check against the spec at
157
+ * POST /api/workflows. Not re-exported from `index.ts`; this is reachable
158
+ * only via deep imports and should not be treated as public API.
159
+ * @internal
160
+ */
161
+ export declare const WORKFLOW_CREATE_PAYLOAD_KEYS: readonly ["jobs", "workflow_edges", "callback_url", "callback_events", "export", "delivery", "processing"];
162
+ export interface GetSchemaOptions {
163
+ /** Filter the schema to operations that accept this MIME type (e.g. `image/jpeg`). */
164
+ mimeType?: string;
165
+ /** Filter the schema to a single operation type. */
166
+ operation?: OperationType;
167
+ /**
168
+ * Conditional revalidation: send the previously-received `ETag` value to
169
+ * receive a 304-not-modified sentinel when the cached response is still
170
+ * fresh. Strong-ETag comparison.
171
+ */
172
+ ifNoneMatch?: string;
173
+ /**
174
+ * Conditional revalidation: send the previously-received `Last-Modified`
175
+ * value (HTTP-date) to receive a 304-not-modified sentinel when the
176
+ * cached response is still fresh.
177
+ */
178
+ ifModifiedSince?: string;
179
+ /** Cancel an in-flight schema fetch. Surfaces as `GislAbortError`. */
180
+ signal?: AbortSignal;
181
+ }
182
+ export type GetSchemaResult = {
183
+ notModified: false;
184
+ data: OperationsSchemaResponse;
185
+ etag?: string;
186
+ lastModified?: string;
187
+ } | {
188
+ notModified: true;
189
+ etag?: string;
190
+ lastModified?: string;
191
+ };
192
+ export interface CreditsUsageOptions {
193
+ /**
194
+ * Page size. Server defaults to 20 and rejects values outside `[1, 100]`
195
+ * with a 400 validation envelope.
196
+ */
197
+ limit?: number;
198
+ /** Page offset (zero-based). Server default is 0. */
199
+ offset?: number;
200
+ }
201
+ /**
202
+ * Aggregated result of a `preflightClips()` batch probe — N parallel calls
203
+ * to `POST /api/uploads/{id}/probe`, partitioned by outcome so the caller
204
+ * can drop bad clips before submitting a long-form merge workflow (per
205
+ * plan v5 round 10 / F11). Aggregation is structural — `ok` is everything
206
+ * the server marked workflow-ready, `rejected` is everything else with a
207
+ * typed probe response, and `errors` carries probe-call failures (e.g.
208
+ * the 422 `feature_not_available` envelope returned while the endpoint is
209
+ * still `availability: planned`).
210
+ */
211
+ export interface PreflightClipsResult {
212
+ /** Probes that returned `probe_status: 'ok'`. Safe to include in a workflow. */
213
+ ok: UploadProbeResponse[];
214
+ /**
215
+ * Probes that returned a non-`ok` `probe_status` (`corrupt`,
216
+ * `unsupported_codec`, `missing_metadata`). The caller should exclude
217
+ * these or convert them first.
218
+ */
219
+ rejected: UploadProbeResponse[];
220
+ /**
221
+ * Probe calls that themselves failed. Includes the
222
+ * `feature_not_available` (422) responses returned while the endpoint
223
+ * is `availability: planned` — narrow on `instanceof
224
+ * GislFeatureNotAvailableError` to detect that case.
225
+ */
226
+ errors: PreflightClipError[];
227
+ }
228
+ export interface PreflightClipError {
229
+ fileId: string;
230
+ error: unknown;
66
231
  }
67
232
  export interface WaitOptions {
68
233
  /** Poll interval in milliseconds (default: 2000) */
@@ -103,4 +268,20 @@ export type GislSseEvent = {
103
268
  export interface UploadOptions {
104
269
  /** Called with bytes uploaded so far (only for multipart) */
105
270
  onProgress?: (uploadedBytes: number, totalBytes: number) => void;
271
+ /**
272
+ * Cancel an in-flight upload. Aborting rejects the `uploadFile` promise with
273
+ * `GislAbortError`. Applies to the API requests (initiate, complete) and
274
+ * every S3 part PUT. Composes with the client-level per-request timeout —
275
+ * whichever callback fires first determines the error class: user abort
276
+ * first → `GislAbortError`; timer first → `GislTimeoutError`.
277
+ */
278
+ signal?: AbortSignal;
279
+ /**
280
+ * Optional metadata hint forwarded to multipart initiate so the server
281
+ * can size-check and preflight-route based on caller-asserted dimensions.
282
+ * Single-shot uploads ignore this field (the multipart initiate is the
283
+ * only endpoint that accepts it). Wire-encoded as a JSON-stringified
284
+ * single FormData field on the multipart/initiate request.
285
+ */
286
+ metadataHint?: MultipartInitiateRequestMetadataHint;
106
287
  }
package/dist/types.js CHANGED
@@ -1,12 +1,33 @@
1
1
  // ---------------------------------------------------------------------------
2
- // Job factory functions
2
+ // Source factories — return wire-format objects with the `type` discriminator
3
3
  // ---------------------------------------------------------------------------
4
- export function fileJob(ref, fileId, operations) {
5
- return { ref, file_id: fileId, operations };
4
+ export function uploadSource(fileId) {
5
+ return { type: 'upload', file_id: fileId };
6
6
  }
7
- export function sourceJob(ref, source, operations) {
8
- return { ref, source, operations };
7
+ export function jobOutputSource(from, operation) {
8
+ return operation === undefined
9
+ ? { type: 'job_output', from }
10
+ : { type: 'job_output', from, operation };
9
11
  }
10
- export function inputsJob(ref, inputs, operations) {
11
- return { ref, inputs, operations };
12
+ export function externalImportSource(externalSourceId) {
13
+ return { type: 'external_import', external_source_id: externalSourceId };
12
14
  }
15
+ export function connectionSource(connectionId, path) {
16
+ return { type: 'connection', connection_id: connectionId, path };
17
+ }
18
+ /**
19
+ * Single source of truth for WorkflowCreatePayload's top-level wire keys.
20
+ * Read by `contract-drift-fields.test.ts` to cross-check against the spec at
21
+ * POST /api/workflows. Not re-exported from `index.ts`; this is reachable
22
+ * only via deep imports and should not be treated as public API.
23
+ * @internal
24
+ */
25
+ export const WORKFLOW_CREATE_PAYLOAD_KEYS = Object.freeze([
26
+ 'jobs',
27
+ 'workflow_edges',
28
+ 'callback_url',
29
+ 'callback_events',
30
+ 'export',
31
+ 'delivery',
32
+ 'processing',
33
+ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giveitsmaller/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "Node.js SDK for the GISL (Give It Smaller) file compression and processing API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "node": ">=18"
20
20
  },
21
21
  "dependencies": {
22
- "@giveitsmaller/contracts": "^0.1.0"
22
+ "@giveitsmaller/contracts": "^0.3.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^22",
@@ -31,6 +31,8 @@
31
31
  "build": "tsc",
32
32
  "prepack": "npm run build",
33
33
  "check": "tsc --noEmit",
34
- "test": "vitest run"
34
+ "test": "vitest run",
35
+ "test:parity": "vitest run tests/parity",
36
+ "parity:update": "UPDATE_PARITY_FIXTURES=1 vitest run tests/parity"
35
37
  }
36
38
  }