@kubun/connector 0.17.2 → 0.17.3

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/lib/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { clusterModelURNs, resolveModelID } from './cluster-utils.js';
3
3
  export { ConnectorError, type ConnectorErrorKind, type ConnectorErrorOptions, classifyHTTPStatus, connectorHTTPError, markWriteSent, } from './errors.js';
4
4
  export { connectorClusters, connectorModelIDs } from './models/cluster.js';
5
5
  export { externalEntityDefinition } from './models/external-entity.js';
6
+ export { type FetchOrAbsentOptions, fetchOrAbsent, isNotFoundError, parseMaxAgeDays, type TargetedRead, } from './provider-utils.js';
6
7
  export type { ActionDefinition, ActionHandler, ActionHandlerFactory, ActionResult, ActionTargetResolver, ActionTargetStorage, ActionWriteContext, ActionWriteResult, ClientDataProvider, ClientProviderFactory, ConnectorAuth, ConnectorDefinition, ConnectorSyncEventPayload, CreatedSourceIDPredictor, DataProvider, DeadLetter, DeviceConnectorAuth, DevicePermission, EntityBatch, EntityRecord, FetchChangesParams, FetchedAbsentEntity, FetchedEntity, FetchedPresentEntity, FetchParams, IntentCanonicalizer, IntentComparison, JSONValue, LocalAnnotationMerger, OAuthConnectorAuth, OAuthState, PendingOp, ReconcileResult, Recovery, ResolvedActionTarget, ServerDataProvider, ServerProviderFactory, SyncBoundary, SyncCompleteEvent, SyncErrorEvent, SyncEvent, SyncFailureSample, SyncProgressCASCurrent, SyncProgressCASResult, SyncProgressEvent, SyncProgressRecompute, SyncState, SyncStateEntry, SyncStateStore, SyncStatus, UserSyncPreferences, WebhookParams, WebhookRegistration, WriteAttachment, } from './types.js';
package/lib/index.js CHANGED
@@ -3,3 +3,4 @@ export { clusterModelURNs, resolveModelID } from './cluster-utils.js';
3
3
  export { ConnectorError, classifyHTTPStatus, connectorHTTPError, markWriteSent } from './errors.js';
4
4
  export { connectorClusters, connectorModelIDs } from './models/cluster.js';
5
5
  export { externalEntityDefinition } from './models/external-entity.js';
6
+ export { fetchOrAbsent, isNotFoundError, parseMaxAgeDays } from './provider-utils.js';
@@ -0,0 +1,13 @@
1
+ import type { EntityRecord, ReconcileResult, SyncBoundary } from './types.js';
2
+ export type TargetedRead = {
3
+ record: EntityRecord;
4
+ providerETag?: string;
5
+ };
6
+ export type FetchOrAbsentOptions = {
7
+ sourceID: string;
8
+ sourceFetchHLC: string;
9
+ read: () => Promise<TargetedRead>;
10
+ };
11
+ export declare function isNotFoundError(err: unknown): boolean;
12
+ export declare function fetchOrAbsent(options: FetchOrAbsentOptions): Promise<ReconcileResult>;
13
+ export declare function parseMaxAgeDays(boundary: SyncBoundary | undefined): number | null;
@@ -0,0 +1,29 @@
1
+ export function isNotFoundError(err) {
2
+ return err?.httpStatus === 404;
3
+ }
4
+ export async function fetchOrAbsent(options) {
5
+ try {
6
+ const { record, providerETag } = await options.read();
7
+ return {
8
+ present: true,
9
+ record,
10
+ sourceFetchHLC: options.sourceFetchHLC,
11
+ ...providerETag != null ? {
12
+ providerETag
13
+ } : {}
14
+ };
15
+ } catch (err) {
16
+ if (isNotFoundError(err)) {
17
+ return {
18
+ present: false,
19
+ sourceID: options.sourceID,
20
+ sourceFetchHLC: options.sourceFetchHLC
21
+ };
22
+ }
23
+ throw err;
24
+ }
25
+ }
26
+ export function parseMaxAgeDays(boundary) {
27
+ const match = boundary?.maxAge != null ? /^P(\d+)D$/i.exec(boundary.maxAge) : null;
28
+ return match?.[1] != null ? Number.parseInt(match[1], 10) : null;
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/connector",
3
- "version": "0.17.2",
3
+ "version": "0.17.3",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@kubun/credential-types": "^0.17.2",
19
- "@kubun/protocol": "^0.17.1",
19
+ "@kubun/protocol": "^0.17.2",
20
20
  "@kubun/scalars": "^0.17.0",
21
21
  "json-schema-typed": "^8.0.2"
22
22
  },