@reopt-ai/data-contract 0.6.3 → 0.7.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.
Files changed (103) hide show
  1. package/dist/client.cjs +228 -321
  2. package/dist/client.cjs.map +1 -1
  3. package/dist/client.d.cts +57 -71
  4. package/dist/client.d.cts.map +1 -0
  5. package/dist/client.d.ts +57 -71
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +228 -322
  8. package/dist/client.js.map +1 -1
  9. package/dist/control.cjs +158 -54
  10. package/dist/control.cjs.map +1 -1
  11. package/dist/control.d.cts +121 -137
  12. package/dist/control.d.cts.map +1 -0
  13. package/dist/control.d.ts +121 -137
  14. package/dist/control.d.ts.map +1 -0
  15. package/dist/control.js +134 -54
  16. package/dist/control.js.map +1 -1
  17. package/dist/events-BUIeU60t.d.cts +142 -0
  18. package/dist/events-BUIeU60t.d.cts.map +1 -0
  19. package/dist/events-BUIeU60t.d.ts +142 -0
  20. package/dist/events-BUIeU60t.d.ts.map +1 -0
  21. package/dist/events.cjs +110 -15
  22. package/dist/events.cjs.map +1 -1
  23. package/dist/events.d.cts +2 -59
  24. package/dist/events.d.ts +2 -59
  25. package/dist/events.js +101 -15
  26. package/dist/events.js.map +1 -1
  27. package/dist/identity.cjs +150 -55
  28. package/dist/identity.cjs.map +1 -1
  29. package/dist/identity.d.cts +21 -20
  30. package/dist/identity.d.cts.map +1 -0
  31. package/dist/identity.d.ts +21 -20
  32. package/dist/identity.d.ts.map +1 -0
  33. package/dist/identity.js +126 -56
  34. package/dist/identity.js.map +1 -1
  35. package/dist/index.cjs +46 -25
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +37 -54
  38. package/dist/index.d.cts.map +1 -0
  39. package/dist/index.d.ts +37 -54
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +36 -25
  42. package/dist/index.js.map +1 -1
  43. package/dist/ingest.cjs +152 -57
  44. package/dist/ingest.cjs.map +1 -1
  45. package/dist/ingest.d.cts +182 -193
  46. package/dist/ingest.d.cts.map +1 -0
  47. package/dist/ingest.d.ts +182 -193
  48. package/dist/ingest.d.ts.map +1 -0
  49. package/dist/ingest.js +126 -57
  50. package/dist/ingest.js.map +1 -1
  51. package/dist/query.cjs +284 -84
  52. package/dist/query.cjs.map +1 -1
  53. package/dist/query.d.cts +456 -469
  54. package/dist/query.d.cts.map +1 -0
  55. package/dist/query.d.ts +456 -469
  56. package/dist/query.d.ts.map +1 -0
  57. package/dist/query.js +245 -84
  58. package/dist/query.js.map +1 -1
  59. package/dist/report.cjs +104 -74
  60. package/dist/report.cjs.map +1 -1
  61. package/dist/report.d.cts +182 -136
  62. package/dist/report.d.cts.map +1 -0
  63. package/dist/report.d.ts +182 -136
  64. package/dist/report.d.ts.map +1 -0
  65. package/dist/report.js +93 -74
  66. package/dist/report.js.map +1 -1
  67. package/dist/version-B_0qb1_K.cjs +53 -0
  68. package/dist/version-B_0qb1_K.cjs.map +1 -0
  69. package/dist/version-C09Cyf4R.js +12 -0
  70. package/dist/version-C09Cyf4R.js.map +1 -0
  71. package/dist/{version-DJ2Grb_N.d.ts → version-CGujUGWd.d.cts} +5 -3
  72. package/dist/version-CGujUGWd.d.cts.map +1 -0
  73. package/dist/{version-DJ2Grb_N.d.cts → version-CGujUGWd.d.ts} +5 -3
  74. package/dist/version-CGujUGWd.d.ts.map +1 -0
  75. package/package.json +69 -28
  76. package/dist/chunk-3EEANNYN.cjs +0 -62
  77. package/dist/chunk-3EEANNYN.cjs.map +0 -1
  78. package/dist/chunk-7W33YGRO.js +0 -160
  79. package/dist/chunk-7W33YGRO.js.map +0 -1
  80. package/dist/chunk-F2RNXJGO.cjs +0 -19
  81. package/dist/chunk-F2RNXJGO.cjs.map +0 -1
  82. package/dist/chunk-FP2X3PRK.js +0 -62
  83. package/dist/chunk-FP2X3PRK.js.map +0 -1
  84. package/dist/chunk-JCEWUSUM.js +0 -53
  85. package/dist/chunk-JCEWUSUM.js.map +0 -1
  86. package/dist/chunk-L3JPDRVG.cjs +0 -160
  87. package/dist/chunk-L3JPDRVG.cjs.map +0 -1
  88. package/dist/chunk-L4KBQAOO.js +0 -204
  89. package/dist/chunk-L4KBQAOO.js.map +0 -1
  90. package/dist/chunk-NJ4JKNBX.js +0 -361
  91. package/dist/chunk-NJ4JKNBX.js.map +0 -1
  92. package/dist/chunk-ORNTN6AK.cjs +0 -53
  93. package/dist/chunk-ORNTN6AK.cjs.map +0 -1
  94. package/dist/chunk-PSUINLW7.js +0 -19
  95. package/dist/chunk-PSUINLW7.js.map +0 -1
  96. package/dist/chunk-RU26QFM2.js +0 -179
  97. package/dist/chunk-RU26QFM2.js.map +0 -1
  98. package/dist/chunk-XDH5QQYF.cjs +0 -361
  99. package/dist/chunk-XDH5QQYF.cjs.map +0 -1
  100. package/dist/chunk-YCTGHWTP.cjs +0 -204
  101. package/dist/chunk-YCTGHWTP.cjs.map +0 -1
  102. package/dist/chunk-ZI6A3WQP.cjs +0 -179
  103. package/dist/chunk-ZI6A3WQP.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/client.cjs","../src/client.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACA;AC4BA,IAAM,WAAA,EAAa,YAAA;AA6GnB,IAAM,SAAA,EAAW;AAAA,EACf,SAAA,EAAW,GAAA;AAAA,EACX,UAAA,EAAY,CAAA;AAAA,EACZ,WAAA,EAAa,GAAA;AAAA,EACb,UAAA,EAAY;AACd,CAAA;AAEA,SAAS,gBAAA,CAAiB,OAAA,EA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C,UAAA;AACuD,UAAA;AACb,UAAA;AACpC,0BAAA;AACR,QAAA;AACF,MAAA;AACiC,MAAA;AACxB,QAAA;AACL,UAAA;AACkB,UAAA;AAClB,UAAA;AAC6C,UAAA;AACb,UAAA;AAC1B,0BAAA;AACR,QAAA;AACF,MAAA;AAC0D,MAAA;AACjD,QAAA;AACL,UAAA;AACkD,UAAA;AACjD,UAAA;AACiD,UAAA;AAClB,UAAA;AAC1B,0BAAA;AACR,QAAA;AACF,MAAA;AAC4C,MAAA;AACnC,QAAA;AACL,UAAA;AACmC,UAAA;AACnC,UAAA;AAC6C,UAAA;AACb,UAAA;AAC1B,0BAAA;AACR,QAAA;AACF,MAAA;AACoD,MAAA;AAC3C,QAAA;AACL,UAAA;AAC8C,UAAA;AAC9C,UAAA;AACyC,UAAA;AACT,UAAA;AAC1B,0BAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AACF,EAAA;AACF;AD5NqJ;AACA;AACA","file":"/Users/eric/reopt-ai/reopt-data/packages/data-contract/dist/client.cjs","sourcesContent":[null,"/**\n * `createDataClient` — typed fetch over the ingest and query planes.\n *\n * Deliberately stateless: no queue, no buffer, no background flush. Batch\n * assembly and cursor management belong to the caller (a forwarder already has\n * a cursor and byte-batching; duplicating that here would give it two).\n *\n * Every response is parsed with the contract schema, so a server that drifts\n * from the contract surfaces as `contract_mismatch` instead of quietly\n * returning something the caller then mis-reads.\n */\nimport {\n CLIENT_ID_HEADER,\n CLIENT_SECRET_HEADER,\n CONTRACT_VERSION,\n CONTRACT_VERSION_HEADER,\n DataApiError,\n REQUEST_ID_HEADER,\n type OptionalClientCredentials,\n} from \"./index.js\";\nimport { zIngestResponse, type IngestResponse, type ITrackHandlerPayload } from \"./ingest.js\";\nimport {\n CONTROL_API_PATHS,\n ORG_KEY_HEADER,\n PLATFORM_KEY_HEADER,\n zCreateOrganizationResponse,\n zCreateProjectResponse,\n zDeleteProjectResponse,\n zRotateClientSecretResponse,\n zRotateOrganizationKeyResponse,\n zUpdateOrganizationQuotaResponse,\n zEventMetaResponse,\n type CreateOrganizationInput,\n type EventMetaResponse,\n type UpsertEventMetaInput,\n type CreateOrganizationResponse,\n type CreateProjectInput,\n type CreateProjectResponse,\n type DeleteProjectInput,\n type DeleteProjectResponse,\n type RotateClientSecretResponse,\n type RotateOrganizationKeyResponse,\n type UpdateOrganizationQuotaInput,\n type UpdateOrganizationQuotaResponse,\n} from \"./control.js\";\nimport {\n QUERY_API_PATHS,\n zEventsTimeseriesResponse,\n zFunnelResponse,\n zRetentionResponse,\n zTrafficOverviewResponse,\n zTrafficSourcesResponse,\n type EventsTimeseriesInput,\n type EventsTimeseriesResponse,\n type FunnelInput,\n type FunnelResponse,\n type RetentionInput,\n type RetentionResponse,\n type TrafficOverviewInput,\n type TrafficOverviewResponse,\n type TrafficSourcesInput,\n type TrafficSourcesResponse,\n} from \"./query.js\";\n\nconst TRACK_PATH = \"/api/track\";\n\nexport interface DataClientRetryOptions {\n /** Attempts after the first. Only 429 and 5xx are retried. Default 2. */\n maxRetries?: number | undefined;\n /** First backoff step; doubles each attempt, with jitter. Default 500ms. */\n baseDelayMs?: number | undefined;\n /** Cap on a single backoff step. Default 20s. */\n maxDelayMs?: number | undefined;\n /** Prefer the server's `Retry-After` over the computed backoff. Default true. */\n respectRetryAfter?: boolean | undefined;\n}\n\nexport interface DataClientOptions extends OptionalClientCredentials {\n /** Origin of the reopt-data deployment, e.g. `https://data.reopt.app`. Trailing slash ignored. */\n baseUrl: string;\n /** Injected so callers can pass a framework-instrumented fetch. Defaults to `globalThis.fetch`. */\n fetch?: typeof globalThis.fetch | undefined;\n /** Per-attempt timeout. Default 10s. */\n timeoutMs?: number | undefined;\n retry?: DataClientRetryOptions | undefined;\n /** Appended to the default `reopt-data-contract/<version>`. */\n userAgent?: string | undefined;\n}\n\nexport interface DataRequestInit {\n signal?: AbortSignal | undefined;\n}\n\n/**\n * Provisioning credentials are passed per call rather than held on the client,\n * because they are a different authority from the client credential the rest of\n * the surface uses — and because a long-lived object holding the platform key\n * is a wider blast radius than a value the caller reads at the moment it needs\n * it.\n */\nexport interface PlatformAuth {\n platformKey: string;\n}\n\nexport interface OrganizationAuth {\n orgKey: string;\n}\n\nexport interface DataClient {\n ingest: {\n /**\n * `POST /api/track`. Send events as one batch; splitting to stay under\n * the 512KB body cap is the caller's job, since only the caller knows how\n * to resume a partially-sent range.\n */\n track(events: ITrackHandlerPayload[], init?: DataRequestInit): Promise<IngestResponse>;\n };\n query: {\n eventsTimeseries(input: EventsTimeseriesInput, init?: DataRequestInit): Promise<EventsTimeseriesResponse>;\n funnel(input: FunnelInput, init?: DataRequestInit): Promise<FunnelResponse>;\n retention(input: RetentionInput, init?: DataRequestInit): Promise<RetentionResponse>;\n trafficOverview(input: TrafficOverviewInput, init?: DataRequestInit): Promise<TrafficOverviewResponse>;\n trafficSources(input: TrafficSourcesInput, init?: DataRequestInit): Promise<TrafficSourcesResponse>;\n };\n control: {\n /** Idempotent on `externalId`. `orgKey` comes back only on first creation. */\n createOrganization(\n input: CreateOrganizationInput,\n auth: PlatformAuth,\n init?: DataRequestInit\n ): Promise<CreateOrganizationResponse>;\n /** Issues a new key and revokes every previous one. The recovery path for a lost key. */\n rotateOrgKey(\n organizationId: string,\n auth: PlatformAuth,\n init?: DataRequestInit\n ): Promise<RotateOrganizationKeyResponse>;\n updateOrganizationQuota(\n organizationId: string,\n input: UpdateOrganizationQuotaInput,\n auth: PlatformAuth,\n init?: DataRequestInit\n ): Promise<UpdateOrganizationQuotaResponse>;\n /** Idempotent on `externalId`. `clientSecret` comes back only on first creation. */\n createProject(\n input: CreateProjectInput,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<CreateProjectResponse>;\n rotateServerClientSecret(\n projectId: string,\n clientId: string,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<RotateClientSecretResponse>;\n /** Irreversible. Idempotent: a project that is already gone still answers 202. */\n deleteProject(\n projectId: string,\n input: DeleteProjectInput,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<DeleteProjectResponse>;\n /** Idempotent: a repeat with the same body changes nothing and answers 200. */\n upsertEventMeta(\n projectId: string,\n name: string,\n input: UpsertEventMetaInput,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<EventMetaResponse>;\n };\n}\n\nconst DEFAULTS = {\n timeoutMs: 10_000,\n maxRetries: 2,\n baseDelayMs: 500,\n maxDelayMs: 20_000,\n} as const;\n\nfunction normalizeBaseUrl(baseUrl: string): string {\n return baseUrl.replace(/\\/+$/, \"\");\n}\n\n/** `Retry-After` is either delta-seconds or an HTTP date; both are legal. */\nfunction parseRetryAfter(header: string | null): number | undefined {\n if (!header) return undefined;\n\n const seconds = Number(header);\n if (Number.isFinite(seconds) && seconds >= 0) return Math.round(seconds * 1000);\n\n const at = Date.parse(header);\n if (Number.isFinite(at)) return Math.max(0, at - Date.now());\n\n return undefined;\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(signal.reason ?? new Error(\"Aborted\"));\n return;\n }\n const timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal?.reason ?? new Error(\"Aborted\"));\n };\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\n/**\n * Every option filled in.\n *\n * Not `Required<T>`: that strips the `?` but keeps the `| undefined` the\n * property declares — which the option types now do, so that callers with\n * `exactOptionalPropertyTypes` can pass a value that may be absent. The whole\n * point of a resolved config is that nothing is absent any more.\n */\ntype Resolved<T> = { [K in keyof T]-?: Exclude<T[K], undefined> };\n\nfunction backoffDelay(attempt: number, retry: Resolved<DataClientRetryOptions>): number {\n const exponential = retry.baseDelayMs * 2 ** attempt;\n const capped = Math.min(exponential, retry.maxDelayMs);\n // Full jitter — a fleet of forwarders that all got 429 should not all come\n // back at the same instant.\n return Math.round(capped * (0.5 + Math.random() * 0.5));\n}\n\n/**\n * Body of a non-2xx response. Both planes share `{ status, code, error, ... }`,\n * so one reader covers them; anything else is reported as `internal_error`\n * with the raw text kept in `details`.\n */\nfunction toApiError(\n status: number,\n rawBody: string,\n retryAfterMs: number | undefined,\n requestId?: string\n): DataApiError {\n let parsed: unknown;\n try {\n parsed = JSON.parse(rawBody);\n } catch {\n return new DataApiError({\n message: `reopt-data responded ${status} with a non-JSON body`,\n status,\n code: status >= 500 ? \"internal_error\" : \"unknown_error\",\n requestId,\n retryAfterMs,\n details: rawBody.slice(0, 2000),\n });\n }\n\n const body = (parsed ?? {}) as Record<string, unknown>;\n const code = typeof body.code === \"string\" ? body.code : status >= 500 ? \"internal_error\" : \"unknown_error\";\n const message =\n (typeof body.message === \"string\" && body.message) ||\n (typeof body.error === \"string\" && body.error) ||\n `reopt-data responded ${status}`;\n\n return new DataApiError({\n message,\n status,\n code,\n requestId: (typeof body.requestId === \"string\" ? body.requestId : undefined) ?? requestId,\n retryAfterMs,\n details: body.errors ?? undefined,\n });\n}\n\nexport function createDataClient(options: DataClientOptions): DataClient {\n const baseUrl = normalizeBaseUrl(options.baseUrl);\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== \"function\") {\n throw new TypeError(\"createDataClient: no fetch implementation available — pass options.fetch\");\n }\n\n const timeoutMs = options.timeoutMs ?? DEFAULTS.timeoutMs;\n const retry: Resolved<DataClientRetryOptions> = {\n maxRetries: options.retry?.maxRetries ?? DEFAULTS.maxRetries,\n baseDelayMs: options.retry?.baseDelayMs ?? DEFAULTS.baseDelayMs,\n maxDelayMs: options.retry?.maxDelayMs ?? DEFAULTS.maxDelayMs,\n respectRetryAfter: options.retry?.respectRetryAfter ?? true,\n };\n\n const userAgent = options.userAgent\n ? `reopt-data-contract/${CONTRACT_VERSION} ${options.userAgent}`\n : `reopt-data-contract/${CONTRACT_VERSION}`;\n\n /**\n * Client credentials, or a clear failure. The ingest and query planes cannot\n * run without them; the provisioning plane never uses them.\n */\n function requireClientCredentials(): { clientId: string; clientSecret: string } {\n if (!options.clientId || !options.clientSecret) {\n throw new DataApiError({\n message:\n \"createDataClient was given no client credentials — pass clientId and clientSecret to use the ingest or query planes\",\n status: 0,\n code: \"credentials_missing\",\n });\n }\n return { clientId: options.clientId, clientSecret: options.clientSecret };\n }\n\n async function requestOnce(\n method: \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\",\n path: string,\n body: unknown,\n extraHeaders: Record<string, string>,\n signal?: AbortSignal\n ): Promise<Response> {\n const controller = new AbortController();\n const timer = setTimeout(\n () => controller.abort(new Error(`reopt-data request timed out after ${timeoutMs}ms`)),\n timeoutMs\n );\n const onCallerAbort = () => controller.abort(signal?.reason ?? new Error(\"Aborted\"));\n signal?.addEventListener(\"abort\", onCallerAbort, { once: true });\n\n try {\n return await doFetch(`${baseUrl}${path}`, {\n method,\n headers: {\n \"content-type\": \"application/json\",\n \"user-agent\": userAgent,\n ...(options.clientId && options.clientSecret\n ? { [CLIENT_ID_HEADER]: options.clientId, [CLIENT_SECRET_HEADER]: options.clientSecret }\n : {}),\n ...extraHeaders,\n },\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", onCallerAbort);\n }\n }\n\n async function send<T>(\n method: \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\",\n path: string,\n body: unknown,\n parse: (value: unknown) => T,\n extraHeaders: Record<string, string> = {},\n signal?: AbortSignal\n ): Promise<T> {\n let lastError: DataApiError | undefined;\n\n for (let attempt = 0; attempt <= retry.maxRetries; attempt++) {\n let response: Response;\n try {\n response = await requestOnce(method, path, body, extraHeaders, signal);\n } catch (cause) {\n // A caller-initiated abort is not a transport failure — propagate it.\n if (signal?.aborted) throw cause;\n lastError = new DataApiError({\n message: cause instanceof Error ? cause.message : String(cause),\n status: 0,\n code: \"network_error\",\n details: cause,\n });\n if (attempt < retry.maxRetries) {\n await sleep(backoffDelay(attempt, retry), signal);\n continue;\n }\n throw lastError;\n }\n\n const requestId = response.headers.get(REQUEST_ID_HEADER) ?? undefined;\n const serverContractVersion = response.headers.get(CONTRACT_VERSION_HEADER);\n const rawBody = await response.text();\n\n if (serverContractVersion !== CONTRACT_VERSION) {\n throw new DataApiError({\n message: serverContractVersion\n ? `reopt-data contract ${serverContractVersion} does not match client contract ${CONTRACT_VERSION}`\n : \"reopt-data response did not declare its contract version\",\n status: response.status,\n code: \"contract_mismatch\",\n requestId,\n details: { expected: CONTRACT_VERSION, received: serverContractVersion },\n });\n }\n\n if (response.ok) {\n let json: unknown;\n try {\n json = JSON.parse(rawBody);\n } catch (cause) {\n throw new DataApiError({\n message: \"reopt-data returned a 2xx with an unparseable body\",\n status: response.status,\n code: \"contract_mismatch\",\n requestId,\n details: cause,\n });\n }\n\n try {\n return parse(json);\n } catch (cause) {\n throw new DataApiError({\n message: \"reopt-data returned a 2xx that does not match the contract\",\n status: response.status,\n code: \"contract_mismatch\",\n requestId,\n details: cause,\n });\n }\n }\n\n const retryAfterMs = retry.respectRetryAfter ? parseRetryAfter(response.headers.get(\"retry-after\")) : undefined;\n lastError = toApiError(response.status, rawBody, retryAfterMs, requestId);\n\n if (!lastError.retryable || attempt === retry.maxRetries) throw lastError;\n await sleep(retryAfterMs ?? backoffDelay(attempt, retry), signal);\n }\n\n /* c8 ignore next -- the loop either returns or throws */\n throw lastError ?? new DataApiError({ message: \"reopt-data request failed\", status: 0, code: \"network_error\" });\n }\n\n /**\n * The ingest and query planes; both require client credentials.\n *\n * `async` so a missing credential rejects rather than throwing\n * synchronously — an async method that sometimes throws before returning a\n * promise slips past every `.catch()` a caller writes.\n */\n async function post<T>(path: string, body: unknown, parse: (value: unknown) => T, signal?: AbortSignal): Promise<T> {\n requireClientCredentials();\n return send(\"POST\", path, body, parse, {}, signal);\n }\n\n return {\n ingest: {\n track(events, init) {\n return post(TRACK_PATH, events, (value) => zIngestResponse.parse(value), init?.signal);\n },\n },\n query: {\n eventsTimeseries(input, init) {\n return post(\n QUERY_API_PATHS.eventsTimeseries,\n input,\n (value) => zEventsTimeseriesResponse.parse(value),\n init?.signal\n );\n },\n funnel(input, init) {\n return post(QUERY_API_PATHS.funnel, input, (value) => zFunnelResponse.parse(value), init?.signal);\n },\n retention(input, init) {\n return post(QUERY_API_PATHS.retention, input, (value) => zRetentionResponse.parse(value), init?.signal);\n },\n trafficOverview(input, init) {\n return post(\n QUERY_API_PATHS.trafficOverview,\n input,\n (value) => zTrafficOverviewResponse.parse(value),\n init?.signal\n );\n },\n trafficSources(input, init) {\n return post(\n QUERY_API_PATHS.trafficSources,\n input,\n (value) => zTrafficSourcesResponse.parse(value),\n init?.signal\n );\n },\n },\n control: {\n createOrganization(input, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.organizations,\n input,\n (value) => zCreateOrganizationResponse.parse(value),\n { [PLATFORM_KEY_HEADER]: auth.platformKey },\n init?.signal\n );\n },\n rotateOrgKey(organizationId, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.organizationKeys(organizationId),\n {},\n (value) => zRotateOrganizationKeyResponse.parse(value),\n { [PLATFORM_KEY_HEADER]: auth.platformKey },\n init?.signal\n );\n },\n updateOrganizationQuota(organizationId, input, auth, init) {\n return send(\n \"PATCH\",\n CONTROL_API_PATHS.organization(organizationId),\n input,\n (value) => zUpdateOrganizationQuotaResponse.parse(value),\n { [PLATFORM_KEY_HEADER]: auth.platformKey },\n init?.signal\n );\n },\n createProject(input, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.projects,\n input,\n (value) => zCreateProjectResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n rotateServerClientSecret(projectId, clientId, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.clientRotate(projectId, clientId),\n {},\n (value) => zRotateClientSecretResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n deleteProject(projectId, input, auth, init) {\n return send(\n \"DELETE\",\n CONTROL_API_PATHS.project(projectId),\n input,\n (value) => zDeleteProjectResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n upsertEventMeta(projectId, name, input, auth, init) {\n return send(\n \"PUT\",\n CONTROL_API_PATHS.projectEvent(projectId, name),\n input,\n (value) => zEventMetaResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n },\n };\n}\n"]}
1
+ {"version":3,"file":"client.cjs","names":["DataApiError","CONTRACT_VERSION","CLIENT_ID_HEADER","CLIENT_SECRET_HEADER","CONTRACT_VERSION_HEADER","zIngestResponse","QUERY_API_PATHS","zEventsTimeseriesResponse","zFunnelResponse","zRetentionResponse","zTrafficOverviewResponse","zTrafficSourcesResponse","CONTROL_API_PATHS","zCreateOrganizationResponse","PLATFORM_KEY_HEADER","zRotateOrganizationKeyResponse","zUpdateOrganizationQuotaResponse","zCreateProjectResponse","ORG_KEY_HEADER","zRotateClientSecretResponse","zDeleteProjectResponse","zEventMetaResponse"],"sources":["../src/client.ts"],"sourcesContent":["/**\n * `createDataClient` — typed fetch over the ingest and query planes.\n *\n * Deliberately stateless: no queue, no buffer, no background flush. Batch\n * assembly and cursor management belong to the caller (a forwarder already has\n * a cursor and byte-batching; duplicating that here would give it two).\n *\n * Every response is parsed with the contract schema, so a server that drifts\n * from the contract surfaces as `contract_mismatch` instead of quietly\n * returning something the caller then mis-reads.\n */\nimport {\n CLIENT_ID_HEADER,\n CLIENT_SECRET_HEADER,\n CONTRACT_VERSION,\n CONTRACT_VERSION_HEADER,\n DataApiError,\n REQUEST_ID_HEADER,\n type OptionalClientCredentials,\n} from \"./index.js\";\nimport { zIngestResponse, type IngestResponse, type ITrackHandlerPayload } from \"./ingest.js\";\nimport {\n CONTROL_API_PATHS,\n ORG_KEY_HEADER,\n PLATFORM_KEY_HEADER,\n zCreateOrganizationResponse,\n zCreateProjectResponse,\n zDeleteProjectResponse,\n zRotateClientSecretResponse,\n zRotateOrganizationKeyResponse,\n zUpdateOrganizationQuotaResponse,\n zEventMetaResponse,\n type CreateOrganizationInput,\n type EventMetaResponse,\n type UpsertEventMetaInput,\n type CreateOrganizationResponse,\n type CreateProjectInput,\n type CreateProjectResponse,\n type DeleteProjectInput,\n type DeleteProjectResponse,\n type RotateClientSecretResponse,\n type RotateOrganizationKeyResponse,\n type UpdateOrganizationQuotaInput,\n type UpdateOrganizationQuotaResponse,\n} from \"./control.js\";\nimport {\n QUERY_API_PATHS,\n zEventsTimeseriesResponse,\n zFunnelResponse,\n zRetentionResponse,\n zTrafficOverviewResponse,\n zTrafficSourcesResponse,\n type EventsTimeseriesInput,\n type EventsTimeseriesResponse,\n type FunnelInput,\n type FunnelResponse,\n type RetentionInput,\n type RetentionResponse,\n type TrafficOverviewInput,\n type TrafficOverviewResponse,\n type TrafficSourcesInput,\n type TrafficSourcesResponse,\n} from \"./query.js\";\n\nconst TRACK_PATH = \"/api/track\";\n\nexport interface DataClientRetryOptions {\n /** Attempts after the first. Only 429 and 5xx are retried. Default 2. */\n maxRetries?: number | undefined;\n /** First backoff step; doubles each attempt, with jitter. Default 500ms. */\n baseDelayMs?: number | undefined;\n /** Cap on a single backoff step. Default 20s. */\n maxDelayMs?: number | undefined;\n /** Prefer the server's `Retry-After` over the computed backoff. Default true. */\n respectRetryAfter?: boolean | undefined;\n}\n\nexport interface DataClientOptions extends OptionalClientCredentials {\n /** Origin of the reopt-data deployment, e.g. `https://data.reopt.app`. Trailing slash ignored. */\n baseUrl: string;\n /** Injected so callers can pass a framework-instrumented fetch. Defaults to `globalThis.fetch`. */\n fetch?: typeof globalThis.fetch | undefined;\n /** Per-attempt timeout. Default 10s. */\n timeoutMs?: number | undefined;\n retry?: DataClientRetryOptions | undefined;\n /** Appended to the default `reopt-data-contract/<version>`. */\n userAgent?: string | undefined;\n}\n\nexport interface DataRequestInit {\n signal?: AbortSignal | undefined;\n}\n\n/**\n * Provisioning credentials are passed per call rather than held on the client,\n * because they are a different authority from the client credential the rest of\n * the surface uses — and because a long-lived object holding the platform key\n * is a wider blast radius than a value the caller reads at the moment it needs\n * it.\n */\nexport interface PlatformAuth {\n platformKey: string;\n}\n\nexport interface OrganizationAuth {\n orgKey: string;\n}\n\nexport interface DataClient {\n ingest: {\n /**\n * `POST /api/track`. Send events as one batch; splitting to stay under\n * the 512KB body cap is the caller's job, since only the caller knows how\n * to resume a partially-sent range.\n */\n track(events: ITrackHandlerPayload[], init?: DataRequestInit): Promise<IngestResponse>;\n };\n query: {\n eventsTimeseries(input: EventsTimeseriesInput, init?: DataRequestInit): Promise<EventsTimeseriesResponse>;\n funnel(input: FunnelInput, init?: DataRequestInit): Promise<FunnelResponse>;\n retention(input: RetentionInput, init?: DataRequestInit): Promise<RetentionResponse>;\n trafficOverview(input: TrafficOverviewInput, init?: DataRequestInit): Promise<TrafficOverviewResponse>;\n trafficSources(input: TrafficSourcesInput, init?: DataRequestInit): Promise<TrafficSourcesResponse>;\n };\n control: {\n /** Idempotent on `externalId`. `orgKey` comes back only on first creation. */\n createOrganization(\n input: CreateOrganizationInput,\n auth: PlatformAuth,\n init?: DataRequestInit\n ): Promise<CreateOrganizationResponse>;\n /** Issues a new key and revokes every previous one. The recovery path for a lost key. */\n rotateOrgKey(\n organizationId: string,\n auth: PlatformAuth,\n init?: DataRequestInit\n ): Promise<RotateOrganizationKeyResponse>;\n updateOrganizationQuota(\n organizationId: string,\n input: UpdateOrganizationQuotaInput,\n auth: PlatformAuth,\n init?: DataRequestInit\n ): Promise<UpdateOrganizationQuotaResponse>;\n /** Idempotent on `externalId`. `clientSecret` comes back only on first creation. */\n createProject(\n input: CreateProjectInput,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<CreateProjectResponse>;\n rotateServerClientSecret(\n projectId: string,\n clientId: string,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<RotateClientSecretResponse>;\n /** Irreversible. Idempotent: a project that is already gone still answers 202. */\n deleteProject(\n projectId: string,\n input: DeleteProjectInput,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<DeleteProjectResponse>;\n /** Idempotent: a repeat with the same body changes nothing and answers 200. */\n upsertEventMeta(\n projectId: string,\n name: string,\n input: UpsertEventMetaInput,\n auth: OrganizationAuth,\n init?: DataRequestInit\n ): Promise<EventMetaResponse>;\n };\n}\n\nconst DEFAULTS = {\n timeoutMs: 10_000,\n maxRetries: 2,\n baseDelayMs: 500,\n maxDelayMs: 20_000,\n} as const;\n\nfunction normalizeBaseUrl(baseUrl: string): string {\n return baseUrl.replace(/\\/+$/, \"\");\n}\n\n/** `Retry-After` is either delta-seconds or an HTTP date; both are legal. */\nfunction parseRetryAfter(header: string | null): number | undefined {\n if (!header) return undefined;\n\n const seconds = Number(header);\n if (Number.isFinite(seconds) && seconds >= 0) return Math.round(seconds * 1000);\n\n const at = Date.parse(header);\n if (Number.isFinite(at)) return Math.max(0, at - Date.now());\n\n return undefined;\n}\n\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(signal.reason ?? new Error(\"Aborted\"));\n return;\n }\n const timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, ms);\n const onAbort = () => {\n clearTimeout(timer);\n reject(signal?.reason ?? new Error(\"Aborted\"));\n };\n signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n}\n\n/**\n * Every option filled in.\n *\n * Not `Required<T>`: that strips the `?` but keeps the `| undefined` the\n * property declares — which the option types now do, so that callers with\n * `exactOptionalPropertyTypes` can pass a value that may be absent. The whole\n * point of a resolved config is that nothing is absent any more.\n */\ntype Resolved<T> = { [K in keyof T]-?: Exclude<T[K], undefined> };\n\nfunction backoffDelay(attempt: number, retry: Resolved<DataClientRetryOptions>): number {\n const exponential = retry.baseDelayMs * 2 ** attempt;\n const capped = Math.min(exponential, retry.maxDelayMs);\n // Full jitter — a fleet of forwarders that all got 429 should not all come\n // back at the same instant.\n return Math.round(capped * (0.5 + Math.random() * 0.5));\n}\n\n/**\n * Body of a non-2xx response. Both planes share `{ status, code, error, ... }`,\n * so one reader covers them; anything else is reported as `internal_error`\n * with the raw text kept in `details`.\n */\nfunction toApiError(\n status: number,\n rawBody: string,\n retryAfterMs: number | undefined,\n requestId?: string\n): DataApiError {\n let parsed: unknown;\n try {\n parsed = JSON.parse(rawBody);\n } catch {\n return new DataApiError({\n message: `reopt-data responded ${status} with a non-JSON body`,\n status,\n code: status >= 500 ? \"internal_error\" : \"unknown_error\",\n requestId,\n retryAfterMs,\n details: rawBody.slice(0, 2000),\n });\n }\n\n const body = (parsed ?? {}) as Record<string, unknown>;\n const code = typeof body.code === \"string\" ? body.code : status >= 500 ? \"internal_error\" : \"unknown_error\";\n const message =\n (typeof body.message === \"string\" && body.message) ||\n (typeof body.error === \"string\" && body.error) ||\n `reopt-data responded ${status}`;\n\n return new DataApiError({\n message,\n status,\n code,\n requestId: (typeof body.requestId === \"string\" ? body.requestId : undefined) ?? requestId,\n retryAfterMs,\n details: body.errors ?? undefined,\n });\n}\n\nexport function createDataClient(options: DataClientOptions): DataClient {\n const baseUrl = normalizeBaseUrl(options.baseUrl);\n const doFetch = options.fetch ?? globalThis.fetch;\n if (typeof doFetch !== \"function\") {\n throw new TypeError(\"createDataClient: no fetch implementation available — pass options.fetch\");\n }\n\n const timeoutMs = options.timeoutMs ?? DEFAULTS.timeoutMs;\n const retry: Resolved<DataClientRetryOptions> = {\n maxRetries: options.retry?.maxRetries ?? DEFAULTS.maxRetries,\n baseDelayMs: options.retry?.baseDelayMs ?? DEFAULTS.baseDelayMs,\n maxDelayMs: options.retry?.maxDelayMs ?? DEFAULTS.maxDelayMs,\n respectRetryAfter: options.retry?.respectRetryAfter ?? true,\n };\n\n const userAgent = options.userAgent\n ? `reopt-data-contract/${CONTRACT_VERSION} ${options.userAgent}`\n : `reopt-data-contract/${CONTRACT_VERSION}`;\n\n /**\n * Client credentials, or a clear failure. The ingest and query planes cannot\n * run without them; the provisioning plane never uses them.\n */\n function requireClientCredentials(): { clientId: string; clientSecret: string } {\n if (!options.clientId || !options.clientSecret) {\n throw new DataApiError({\n message:\n \"createDataClient was given no client credentials — pass clientId and clientSecret to use the ingest or query planes\",\n status: 0,\n code: \"credentials_missing\",\n });\n }\n return { clientId: options.clientId, clientSecret: options.clientSecret };\n }\n\n async function requestOnce(\n method: \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\",\n path: string,\n body: unknown,\n extraHeaders: Record<string, string>,\n signal?: AbortSignal\n ): Promise<Response> {\n const controller = new AbortController();\n const timer = setTimeout(\n () => controller.abort(new Error(`reopt-data request timed out after ${timeoutMs}ms`)),\n timeoutMs\n );\n const onCallerAbort = () => controller.abort(signal?.reason ?? new Error(\"Aborted\"));\n signal?.addEventListener(\"abort\", onCallerAbort, { once: true });\n\n try {\n return await doFetch(`${baseUrl}${path}`, {\n method,\n headers: {\n \"content-type\": \"application/json\",\n \"user-agent\": userAgent,\n ...(options.clientId && options.clientSecret\n ? { [CLIENT_ID_HEADER]: options.clientId, [CLIENT_SECRET_HEADER]: options.clientSecret }\n : {}),\n ...extraHeaders,\n },\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } finally {\n clearTimeout(timer);\n signal?.removeEventListener(\"abort\", onCallerAbort);\n }\n }\n\n async function send<T>(\n method: \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\",\n path: string,\n body: unknown,\n parse: (value: unknown) => T,\n extraHeaders: Record<string, string> = {},\n signal?: AbortSignal\n ): Promise<T> {\n let lastError: DataApiError | undefined;\n\n for (let attempt = 0; attempt <= retry.maxRetries; attempt++) {\n let response: Response;\n try {\n response = await requestOnce(method, path, body, extraHeaders, signal);\n } catch (cause) {\n // A caller-initiated abort is not a transport failure — propagate it.\n if (signal?.aborted) throw cause;\n lastError = new DataApiError({\n message: cause instanceof Error ? cause.message : String(cause),\n status: 0,\n code: \"network_error\",\n details: cause,\n });\n if (attempt < retry.maxRetries) {\n await sleep(backoffDelay(attempt, retry), signal);\n continue;\n }\n throw lastError;\n }\n\n const requestId = response.headers.get(REQUEST_ID_HEADER) ?? undefined;\n const serverContractVersion = response.headers.get(CONTRACT_VERSION_HEADER);\n const rawBody = await response.text();\n\n if (serverContractVersion !== CONTRACT_VERSION) {\n throw new DataApiError({\n message: serverContractVersion\n ? `reopt-data contract ${serverContractVersion} does not match client contract ${CONTRACT_VERSION}`\n : \"reopt-data response did not declare its contract version\",\n status: response.status,\n code: \"contract_mismatch\",\n requestId,\n details: { expected: CONTRACT_VERSION, received: serverContractVersion },\n });\n }\n\n if (response.ok) {\n let json: unknown;\n try {\n json = JSON.parse(rawBody);\n } catch (cause) {\n throw new DataApiError({\n message: \"reopt-data returned a 2xx with an unparseable body\",\n status: response.status,\n code: \"contract_mismatch\",\n requestId,\n details: cause,\n });\n }\n\n try {\n return parse(json);\n } catch (cause) {\n throw new DataApiError({\n message: \"reopt-data returned a 2xx that does not match the contract\",\n status: response.status,\n code: \"contract_mismatch\",\n requestId,\n details: cause,\n });\n }\n }\n\n const retryAfterMs = retry.respectRetryAfter ? parseRetryAfter(response.headers.get(\"retry-after\")) : undefined;\n lastError = toApiError(response.status, rawBody, retryAfterMs, requestId);\n\n if (!lastError.retryable || attempt === retry.maxRetries) throw lastError;\n await sleep(retryAfterMs ?? backoffDelay(attempt, retry), signal);\n }\n\n /* c8 ignore next -- the loop either returns or throws */\n throw lastError ?? new DataApiError({ message: \"reopt-data request failed\", status: 0, code: \"network_error\" });\n }\n\n /**\n * The ingest and query planes; both require client credentials.\n *\n * `async` so a missing credential rejects rather than throwing\n * synchronously — an async method that sometimes throws before returning a\n * promise slips past every `.catch()` a caller writes.\n */\n async function post<T>(path: string, body: unknown, parse: (value: unknown) => T, signal?: AbortSignal): Promise<T> {\n requireClientCredentials();\n return send(\"POST\", path, body, parse, {}, signal);\n }\n\n return {\n ingest: {\n track(events, init) {\n return post(TRACK_PATH, events, (value) => zIngestResponse.parse(value), init?.signal);\n },\n },\n query: {\n eventsTimeseries(input, init) {\n return post(\n QUERY_API_PATHS.eventsTimeseries,\n input,\n (value) => zEventsTimeseriesResponse.parse(value),\n init?.signal\n );\n },\n funnel(input, init) {\n return post(QUERY_API_PATHS.funnel, input, (value) => zFunnelResponse.parse(value), init?.signal);\n },\n retention(input, init) {\n return post(QUERY_API_PATHS.retention, input, (value) => zRetentionResponse.parse(value), init?.signal);\n },\n trafficOverview(input, init) {\n return post(\n QUERY_API_PATHS.trafficOverview,\n input,\n (value) => zTrafficOverviewResponse.parse(value),\n init?.signal\n );\n },\n trafficSources(input, init) {\n return post(\n QUERY_API_PATHS.trafficSources,\n input,\n (value) => zTrafficSourcesResponse.parse(value),\n init?.signal\n );\n },\n },\n control: {\n createOrganization(input, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.organizations,\n input,\n (value) => zCreateOrganizationResponse.parse(value),\n { [PLATFORM_KEY_HEADER]: auth.platformKey },\n init?.signal\n );\n },\n rotateOrgKey(organizationId, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.organizationKeys(organizationId),\n {},\n (value) => zRotateOrganizationKeyResponse.parse(value),\n { [PLATFORM_KEY_HEADER]: auth.platformKey },\n init?.signal\n );\n },\n updateOrganizationQuota(organizationId, input, auth, init) {\n return send(\n \"PATCH\",\n CONTROL_API_PATHS.organization(organizationId),\n input,\n (value) => zUpdateOrganizationQuotaResponse.parse(value),\n { [PLATFORM_KEY_HEADER]: auth.platformKey },\n init?.signal\n );\n },\n createProject(input, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.projects,\n input,\n (value) => zCreateProjectResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n rotateServerClientSecret(projectId, clientId, auth, init) {\n return send(\n \"POST\",\n CONTROL_API_PATHS.clientRotate(projectId, clientId),\n {},\n (value) => zRotateClientSecretResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n deleteProject(projectId, input, auth, init) {\n return send(\n \"DELETE\",\n CONTROL_API_PATHS.project(projectId),\n input,\n (value) => zDeleteProjectResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n upsertEventMeta(projectId, name, input, auth, init) {\n return send(\n \"PUT\",\n CONTROL_API_PATHS.projectEvent(projectId, name),\n input,\n (value) => zEventMetaResponse.parse(value),\n { [ORG_KEY_HEADER]: auth.orgKey },\n init?.signal\n );\n },\n },\n };\n}\n"],"mappings":";;;;;;;AAgEA,MAAM,aAAa;AA6GnB,MAAM,WAAW;CACf,WAAW;CACX,YAAY;CACZ,aAAa;CACb,YAAY;AACd;AAEA,SAAS,iBAAiB,SAAyB;CACjD,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AACnC;AAGA,SAAS,gBAAgB,QAA2C;CAClE,IAAI,CAAC,QAAQ,OAAO,KAAA;CAEpB,MAAM,UAAU,OAAO,MAAM;CAC7B,IAAI,OAAO,SAAS,OAAO,KAAK,WAAW,GAAG,OAAO,KAAK,MAAM,UAAU,GAAI;CAE9E,MAAM,KAAK,KAAK,MAAM,MAAM;CAC5B,IAAI,OAAO,SAAS,EAAE,GAAG,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC;AAG7D;AAEA,SAAS,MAAM,IAAY,QAAqC;CAC9D,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,IAAI,QAAQ,SAAS;GACnB,OAAO,OAAO,UAAU,IAAI,MAAM,SAAS,CAAC;GAC5C;EACF;EACA,MAAM,QAAQ,iBAAiB;GAC7B,QAAQ,oBAAoB,SAAS,OAAO;GAC5C,QAAQ;EACV,GAAG,EAAE;EACL,MAAM,gBAAgB;GACpB,aAAa,KAAK;GAClB,OAAO,QAAQ,UAAU,IAAI,MAAM,SAAS,CAAC;EAC/C;EACA,QAAQ,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAC3D,CAAC;AACH;AAYA,SAAS,aAAa,SAAiB,OAAiD;CAC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B,MAAM,KAAK,GACrD,GAAGD,gBAAAA,sBAAsB,KAAK,YAAY,GAC1C,MAAM,MACR;GACF;GACA,wBAAwB,gBAAgB,OAAO,MAAM,MAAM;IACzD,OAAO,KACL,SACAF,gBAAAA,kBAAkB,aAAa,cAAc,GAC7C,QACC,UAAUI,gBAAAA,iCAAiC,MAAM,KAAK,GACvD,GAAGF,gBAAAA,sBAAsB,KAAK,YAAY,GAC1C,MAAM,MACR;GACF;GACA,cAAc,OAAO,MAAM,MAAM;IAC/B,OAAO,KACL,QACAF,gBAAAA,kBAAkB,UAClB,QACC,UAAUK,gBAAAA,uBAAuB,MAAM,KAAK,GAC7C,GAAGC,gBAAAA,iBAAiB,KAAK,OAAO,GAChC,MAAM,MACR;GACF;GACA,yBAAyB,WAAW,UAAU,MAAM,MAAM;IACxD,OAAO,KACL,QACAN,gBAAAA,kBAAkB,aAAa,WAAW,QAAQ,GAClD,CAAC,IACA,UAAUO,gBAAAA,4BAA4B,MAAM,KAAK,GAClD,GAAGD,gBAAAA,iBAAiB,KAAK,OAAO,GAChC,MAAM,MACR;GACF;GACA,cAAc,WAAW,OAAO,MAAM,MAAM;IAC1C,OAAO,KACL,UACAN,gBAAAA,kBAAkB,QAAQ,SAAS,GACnC,QACC,UAAUQ,gBAAAA,uBAAuB,MAAM,KAAK,GAC7C,GAAGF,gBAAAA,iBAAiB,KAAK,OAAO,GAChC,MAAM,MACR;GACF;GACA,gBAAgB,WAAW,MAAM,OAAO,MAAM,MAAM;IAClD,OAAO,KACL,OACAN,gBAAAA,kBAAkB,aAAa,WAAW,IAAI,GAC9C,QACC,UAAUS,gBAAAA,mBAAmB,MAAM,KAAK,GACzC,GAAGH,gBAAAA,iBAAiB,KAAK,OAAO,GAChC,MAAM,MACR;GACF;EACF;CACF;AACF"}
package/dist/client.d.cts CHANGED
@@ -1,46 +1,31 @@
1
- import { OptionalClientCredentials } from './index.cjs';
2
- import { ITrackHandlerPayload, IngestResponse } from './ingest.cjs';
3
- import { CreateOrganizationInput, CreateOrganizationResponse, RotateOrganizationKeyResponse, UpdateOrganizationQuotaInput, UpdateOrganizationQuotaResponse, CreateProjectInput, CreateProjectResponse, RotateClientSecretResponse, DeleteProjectInput, DeleteProjectResponse, UpsertEventMetaInput, EventMetaResponse } from './control.cjs';
4
- import { EventsTimeseriesInput, EventsTimeseriesResponse, FunnelInput, FunnelResponse, RetentionInput, RetentionResponse, TrafficOverviewInput, TrafficOverviewResponse, TrafficSourcesInput, TrafficSourcesResponse } from './query.cjs';
5
- import 'zod';
6
- import './version-DJ2Grb_N.cjs';
7
- import './events.cjs';
8
-
9
- /**
10
- * `createDataClient` — typed fetch over the ingest and query planes.
11
- *
12
- * Deliberately stateless: no queue, no buffer, no background flush. Batch
13
- * assembly and cursor management belong to the caller (a forwarder already has
14
- * a cursor and byte-batching; duplicating that here would give it two).
15
- *
16
- * Every response is parsed with the contract schema, so a server that drifts
17
- * from the contract surfaces as `contract_mismatch` instead of quietly
18
- * returning something the caller then mis-reads.
19
- */
20
-
1
+ import { OptionalClientCredentials } from "./index.cjs";
2
+ import { ITrackHandlerPayload, IngestResponse } from "./ingest.cjs";
3
+ import { CreateOrganizationInput, CreateOrganizationResponse, CreateProjectInput, CreateProjectResponse, DeleteProjectInput, DeleteProjectResponse, EventMetaResponse, RotateClientSecretResponse, RotateOrganizationKeyResponse, UpdateOrganizationQuotaInput, UpdateOrganizationQuotaResponse, UpsertEventMetaInput } from "./control.cjs";
4
+ import { EventsTimeseriesInput, EventsTimeseriesResponse, FunnelInput, FunnelResponse, RetentionInput, RetentionResponse, TrafficOverviewInput, TrafficOverviewResponse, TrafficSourcesInput, TrafficSourcesResponse } from "./query.cjs";
5
+ //#region src/client.d.ts
21
6
  interface DataClientRetryOptions {
22
- /** Attempts after the first. Only 429 and 5xx are retried. Default 2. */
23
- maxRetries?: number | undefined;
24
- /** First backoff step; doubles each attempt, with jitter. Default 500ms. */
25
- baseDelayMs?: number | undefined;
26
- /** Cap on a single backoff step. Default 20s. */
27
- maxDelayMs?: number | undefined;
28
- /** Prefer the server's `Retry-After` over the computed backoff. Default true. */
29
- respectRetryAfter?: boolean | undefined;
7
+ /** Attempts after the first. Only 429 and 5xx are retried. Default 2. */
8
+ maxRetries?: number | undefined;
9
+ /** First backoff step; doubles each attempt, with jitter. Default 500ms. */
10
+ baseDelayMs?: number | undefined;
11
+ /** Cap on a single backoff step. Default 20s. */
12
+ maxDelayMs?: number | undefined;
13
+ /** Prefer the server's `Retry-After` over the computed backoff. Default true. */
14
+ respectRetryAfter?: boolean | undefined;
30
15
  }
31
16
  interface DataClientOptions extends OptionalClientCredentials {
32
- /** Origin of the reopt-data deployment, e.g. `https://data.reopt.app`. Trailing slash ignored. */
33
- baseUrl: string;
34
- /** Injected so callers can pass a framework-instrumented fetch. Defaults to `globalThis.fetch`. */
35
- fetch?: typeof globalThis.fetch | undefined;
36
- /** Per-attempt timeout. Default 10s. */
37
- timeoutMs?: number | undefined;
38
- retry?: DataClientRetryOptions | undefined;
39
- /** Appended to the default `reopt-data-contract/<version>`. */
40
- userAgent?: string | undefined;
17
+ /** Origin of the reopt-data deployment, e.g. `https://data.reopt.app`. Trailing slash ignored. */
18
+ baseUrl: string;
19
+ /** Injected so callers can pass a framework-instrumented fetch. Defaults to `globalThis.fetch`. */
20
+ fetch?: typeof globalThis.fetch | undefined;
21
+ /** Per-attempt timeout. Default 10s. */
22
+ timeoutMs?: number | undefined;
23
+ retry?: DataClientRetryOptions | undefined;
24
+ /** Appended to the default `reopt-data-contract/<version>`. */
25
+ userAgent?: string | undefined;
41
26
  }
42
27
  interface DataRequestInit {
43
- signal?: AbortSignal | undefined;
28
+ signal?: AbortSignal | undefined;
44
29
  }
45
30
  /**
46
31
  * Provisioning credentials are passed per call rather than held on the client,
@@ -50,42 +35,43 @@ interface DataRequestInit {
50
35
  * it.
51
36
  */
52
37
  interface PlatformAuth {
53
- platformKey: string;
38
+ platformKey: string;
54
39
  }
55
40
  interface OrganizationAuth {
56
- orgKey: string;
41
+ orgKey: string;
57
42
  }
58
43
  interface DataClient {
59
- ingest: {
60
- /**
61
- * `POST /api/track`. Send events as one batch; splitting to stay under
62
- * the 512KB body cap is the caller's job, since only the caller knows how
63
- * to resume a partially-sent range.
64
- */
65
- track(events: ITrackHandlerPayload[], init?: DataRequestInit): Promise<IngestResponse>;
66
- };
67
- query: {
68
- eventsTimeseries(input: EventsTimeseriesInput, init?: DataRequestInit): Promise<EventsTimeseriesResponse>;
69
- funnel(input: FunnelInput, init?: DataRequestInit): Promise<FunnelResponse>;
70
- retention(input: RetentionInput, init?: DataRequestInit): Promise<RetentionResponse>;
71
- trafficOverview(input: TrafficOverviewInput, init?: DataRequestInit): Promise<TrafficOverviewResponse>;
72
- trafficSources(input: TrafficSourcesInput, init?: DataRequestInit): Promise<TrafficSourcesResponse>;
73
- };
74
- control: {
75
- /** Idempotent on `externalId`. `orgKey` comes back only on first creation. */
76
- createOrganization(input: CreateOrganizationInput, auth: PlatformAuth, init?: DataRequestInit): Promise<CreateOrganizationResponse>;
77
- /** Issues a new key and revokes every previous one. The recovery path for a lost key. */
78
- rotateOrgKey(organizationId: string, auth: PlatformAuth, init?: DataRequestInit): Promise<RotateOrganizationKeyResponse>;
79
- updateOrganizationQuota(organizationId: string, input: UpdateOrganizationQuotaInput, auth: PlatformAuth, init?: DataRequestInit): Promise<UpdateOrganizationQuotaResponse>;
80
- /** Idempotent on `externalId`. `clientSecret` comes back only on first creation. */
81
- createProject(input: CreateProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<CreateProjectResponse>;
82
- rotateServerClientSecret(projectId: string, clientId: string, auth: OrganizationAuth, init?: DataRequestInit): Promise<RotateClientSecretResponse>;
83
- /** Irreversible. Idempotent: a project that is already gone still answers 202. */
84
- deleteProject(projectId: string, input: DeleteProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<DeleteProjectResponse>;
85
- /** Idempotent: a repeat with the same body changes nothing and answers 200. */
86
- upsertEventMeta(projectId: string, name: string, input: UpsertEventMetaInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<EventMetaResponse>;
87
- };
44
+ ingest: {
45
+ /**
46
+ * `POST /api/track`. Send events as one batch; splitting to stay under
47
+ * the 512KB body cap is the caller's job, since only the caller knows how
48
+ * to resume a partially-sent range.
49
+ */
50
+ track(events: ITrackHandlerPayload[], init?: DataRequestInit): Promise<IngestResponse>;
51
+ };
52
+ query: {
53
+ eventsTimeseries(input: EventsTimeseriesInput, init?: DataRequestInit): Promise<EventsTimeseriesResponse>;
54
+ funnel(input: FunnelInput, init?: DataRequestInit): Promise<FunnelResponse>;
55
+ retention(input: RetentionInput, init?: DataRequestInit): Promise<RetentionResponse>;
56
+ trafficOverview(input: TrafficOverviewInput, init?: DataRequestInit): Promise<TrafficOverviewResponse>;
57
+ trafficSources(input: TrafficSourcesInput, init?: DataRequestInit): Promise<TrafficSourcesResponse>;
58
+ };
59
+ control: {
60
+ /** Idempotent on `externalId`. `orgKey` comes back only on first creation. */
61
+ createOrganization(input: CreateOrganizationInput, auth: PlatformAuth, init?: DataRequestInit): Promise<CreateOrganizationResponse>;
62
+ /** Issues a new key and revokes every previous one. The recovery path for a lost key. */
63
+ rotateOrgKey(organizationId: string, auth: PlatformAuth, init?: DataRequestInit): Promise<RotateOrganizationKeyResponse>;
64
+ updateOrganizationQuota(organizationId: string, input: UpdateOrganizationQuotaInput, auth: PlatformAuth, init?: DataRequestInit): Promise<UpdateOrganizationQuotaResponse>;
65
+ /** Idempotent on `externalId`. `clientSecret` comes back only on first creation. */
66
+ createProject(input: CreateProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<CreateProjectResponse>;
67
+ rotateServerClientSecret(projectId: string, clientId: string, auth: OrganizationAuth, init?: DataRequestInit): Promise<RotateClientSecretResponse>;
68
+ /** Irreversible. Idempotent: a project that is already gone still answers 202. */
69
+ deleteProject(projectId: string, input: DeleteProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<DeleteProjectResponse>;
70
+ /** Idempotent: a repeat with the same body changes nothing and answers 200. */
71
+ upsertEventMeta(projectId: string, name: string, input: UpsertEventMetaInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<EventMetaResponse>;
72
+ };
88
73
  }
89
74
  declare function createDataClient(options: DataClientOptions): DataClient;
90
-
91
- export { type DataClient, type DataClientOptions, type DataClientRetryOptions, type DataRequestInit, type OrganizationAuth, type PlatformAuth, createDataClient };
75
+ //#endregion
76
+ export { DataClient, DataClientOptions, DataClientRetryOptions, DataRequestInit, OrganizationAuth, PlatformAuth, createDataClient };
77
+ //# sourceMappingURL=client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;UAkEiB;;EAEf;;EAEA;;EAEA;;EAEA;;UAGe,0BAA0B;;EAEzC;;EAEA,eAAe,WAAW;;EAE1B;EACA,QAAQ;;EAER;;UAGe;EACf,SAAS;;;;;;;;;UAUM;EACf;;UAGe;EACf;;UAGe;EACf;;;;;;IAME,MAAM,QAAQ,wBAAwB,OAAO,kBAAkB,QAAQ;;EAEzE;IACE,iBAAiB,OAAO,uBAAuB,OAAO,kBAAkB,QAAQ;IAChF,OAAO,OAAO,aAAa,OAAO,kBAAkB,QAAQ;IAC5D,UAAU,OAAO,gBAAgB,OAAO,kBAAkB,QAAQ;IAClE,gBAAgB,OAAO,sBAAsB,OAAO,kBAAkB,QAAQ;IAC9E,eAAe,OAAO,qBAAqB,OAAO,kBAAkB,QAAQ;;EAE9E;;IAEE,mBACE,OAAO,yBACP,MAAM,cACN,OAAO,kBACN,QAAQ;;IAEX,aACE,wBACA,MAAM,cACN,OAAO,kBACN,QAAQ;IACX,wBACE,wBACA,OAAO,8BACP,MAAM,cACN,OAAO,kBACN,QAAQ;;IAEX,cACE,OAAO,oBACP,MAAM,kBACN,OAAO,kBACN,QAAQ;IACX,yBACE,mBACA,kBACA,MAAM,kBACN,OAAO,kBACN,QAAQ;;IAEX,cACE,mBACA,OAAO,oBACP,MAAM,kBACN,OAAO,kBACN,QAAQ;;IAEX,gBACE,mBACA,cACA,OAAO,sBACP,MAAM,kBACN,OAAO,kBACN,QAAQ;;;iBA0GC,iBAAiB,SAAS,oBAAoB"}
package/dist/client.d.ts CHANGED
@@ -1,46 +1,31 @@
1
- import { OptionalClientCredentials } from './index.js';
2
- import { ITrackHandlerPayload, IngestResponse } from './ingest.js';
3
- import { CreateOrganizationInput, CreateOrganizationResponse, RotateOrganizationKeyResponse, UpdateOrganizationQuotaInput, UpdateOrganizationQuotaResponse, CreateProjectInput, CreateProjectResponse, RotateClientSecretResponse, DeleteProjectInput, DeleteProjectResponse, UpsertEventMetaInput, EventMetaResponse } from './control.js';
4
- import { EventsTimeseriesInput, EventsTimeseriesResponse, FunnelInput, FunnelResponse, RetentionInput, RetentionResponse, TrafficOverviewInput, TrafficOverviewResponse, TrafficSourcesInput, TrafficSourcesResponse } from './query.js';
5
- import 'zod';
6
- import './version-DJ2Grb_N.js';
7
- import './events.js';
8
-
9
- /**
10
- * `createDataClient` — typed fetch over the ingest and query planes.
11
- *
12
- * Deliberately stateless: no queue, no buffer, no background flush. Batch
13
- * assembly and cursor management belong to the caller (a forwarder already has
14
- * a cursor and byte-batching; duplicating that here would give it two).
15
- *
16
- * Every response is parsed with the contract schema, so a server that drifts
17
- * from the contract surfaces as `contract_mismatch` instead of quietly
18
- * returning something the caller then mis-reads.
19
- */
20
-
1
+ import { OptionalClientCredentials } from "./index.js";
2
+ import { ITrackHandlerPayload, IngestResponse } from "./ingest.js";
3
+ import { CreateOrganizationInput, CreateOrganizationResponse, CreateProjectInput, CreateProjectResponse, DeleteProjectInput, DeleteProjectResponse, EventMetaResponse, RotateClientSecretResponse, RotateOrganizationKeyResponse, UpdateOrganizationQuotaInput, UpdateOrganizationQuotaResponse, UpsertEventMetaInput } from "./control.js";
4
+ import { EventsTimeseriesInput, EventsTimeseriesResponse, FunnelInput, FunnelResponse, RetentionInput, RetentionResponse, TrafficOverviewInput, TrafficOverviewResponse, TrafficSourcesInput, TrafficSourcesResponse } from "./query.js";
5
+ //#region src/client.d.ts
21
6
  interface DataClientRetryOptions {
22
- /** Attempts after the first. Only 429 and 5xx are retried. Default 2. */
23
- maxRetries?: number | undefined;
24
- /** First backoff step; doubles each attempt, with jitter. Default 500ms. */
25
- baseDelayMs?: number | undefined;
26
- /** Cap on a single backoff step. Default 20s. */
27
- maxDelayMs?: number | undefined;
28
- /** Prefer the server's `Retry-After` over the computed backoff. Default true. */
29
- respectRetryAfter?: boolean | undefined;
7
+ /** Attempts after the first. Only 429 and 5xx are retried. Default 2. */
8
+ maxRetries?: number | undefined;
9
+ /** First backoff step; doubles each attempt, with jitter. Default 500ms. */
10
+ baseDelayMs?: number | undefined;
11
+ /** Cap on a single backoff step. Default 20s. */
12
+ maxDelayMs?: number | undefined;
13
+ /** Prefer the server's `Retry-After` over the computed backoff. Default true. */
14
+ respectRetryAfter?: boolean | undefined;
30
15
  }
31
16
  interface DataClientOptions extends OptionalClientCredentials {
32
- /** Origin of the reopt-data deployment, e.g. `https://data.reopt.app`. Trailing slash ignored. */
33
- baseUrl: string;
34
- /** Injected so callers can pass a framework-instrumented fetch. Defaults to `globalThis.fetch`. */
35
- fetch?: typeof globalThis.fetch | undefined;
36
- /** Per-attempt timeout. Default 10s. */
37
- timeoutMs?: number | undefined;
38
- retry?: DataClientRetryOptions | undefined;
39
- /** Appended to the default `reopt-data-contract/<version>`. */
40
- userAgent?: string | undefined;
17
+ /** Origin of the reopt-data deployment, e.g. `https://data.reopt.app`. Trailing slash ignored. */
18
+ baseUrl: string;
19
+ /** Injected so callers can pass a framework-instrumented fetch. Defaults to `globalThis.fetch`. */
20
+ fetch?: typeof globalThis.fetch | undefined;
21
+ /** Per-attempt timeout. Default 10s. */
22
+ timeoutMs?: number | undefined;
23
+ retry?: DataClientRetryOptions | undefined;
24
+ /** Appended to the default `reopt-data-contract/<version>`. */
25
+ userAgent?: string | undefined;
41
26
  }
42
27
  interface DataRequestInit {
43
- signal?: AbortSignal | undefined;
28
+ signal?: AbortSignal | undefined;
44
29
  }
45
30
  /**
46
31
  * Provisioning credentials are passed per call rather than held on the client,
@@ -50,42 +35,43 @@ interface DataRequestInit {
50
35
  * it.
51
36
  */
52
37
  interface PlatformAuth {
53
- platformKey: string;
38
+ platformKey: string;
54
39
  }
55
40
  interface OrganizationAuth {
56
- orgKey: string;
41
+ orgKey: string;
57
42
  }
58
43
  interface DataClient {
59
- ingest: {
60
- /**
61
- * `POST /api/track`. Send events as one batch; splitting to stay under
62
- * the 512KB body cap is the caller's job, since only the caller knows how
63
- * to resume a partially-sent range.
64
- */
65
- track(events: ITrackHandlerPayload[], init?: DataRequestInit): Promise<IngestResponse>;
66
- };
67
- query: {
68
- eventsTimeseries(input: EventsTimeseriesInput, init?: DataRequestInit): Promise<EventsTimeseriesResponse>;
69
- funnel(input: FunnelInput, init?: DataRequestInit): Promise<FunnelResponse>;
70
- retention(input: RetentionInput, init?: DataRequestInit): Promise<RetentionResponse>;
71
- trafficOverview(input: TrafficOverviewInput, init?: DataRequestInit): Promise<TrafficOverviewResponse>;
72
- trafficSources(input: TrafficSourcesInput, init?: DataRequestInit): Promise<TrafficSourcesResponse>;
73
- };
74
- control: {
75
- /** Idempotent on `externalId`. `orgKey` comes back only on first creation. */
76
- createOrganization(input: CreateOrganizationInput, auth: PlatformAuth, init?: DataRequestInit): Promise<CreateOrganizationResponse>;
77
- /** Issues a new key and revokes every previous one. The recovery path for a lost key. */
78
- rotateOrgKey(organizationId: string, auth: PlatformAuth, init?: DataRequestInit): Promise<RotateOrganizationKeyResponse>;
79
- updateOrganizationQuota(organizationId: string, input: UpdateOrganizationQuotaInput, auth: PlatformAuth, init?: DataRequestInit): Promise<UpdateOrganizationQuotaResponse>;
80
- /** Idempotent on `externalId`. `clientSecret` comes back only on first creation. */
81
- createProject(input: CreateProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<CreateProjectResponse>;
82
- rotateServerClientSecret(projectId: string, clientId: string, auth: OrganizationAuth, init?: DataRequestInit): Promise<RotateClientSecretResponse>;
83
- /** Irreversible. Idempotent: a project that is already gone still answers 202. */
84
- deleteProject(projectId: string, input: DeleteProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<DeleteProjectResponse>;
85
- /** Idempotent: a repeat with the same body changes nothing and answers 200. */
86
- upsertEventMeta(projectId: string, name: string, input: UpsertEventMetaInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<EventMetaResponse>;
87
- };
44
+ ingest: {
45
+ /**
46
+ * `POST /api/track`. Send events as one batch; splitting to stay under
47
+ * the 512KB body cap is the caller's job, since only the caller knows how
48
+ * to resume a partially-sent range.
49
+ */
50
+ track(events: ITrackHandlerPayload[], init?: DataRequestInit): Promise<IngestResponse>;
51
+ };
52
+ query: {
53
+ eventsTimeseries(input: EventsTimeseriesInput, init?: DataRequestInit): Promise<EventsTimeseriesResponse>;
54
+ funnel(input: FunnelInput, init?: DataRequestInit): Promise<FunnelResponse>;
55
+ retention(input: RetentionInput, init?: DataRequestInit): Promise<RetentionResponse>;
56
+ trafficOverview(input: TrafficOverviewInput, init?: DataRequestInit): Promise<TrafficOverviewResponse>;
57
+ trafficSources(input: TrafficSourcesInput, init?: DataRequestInit): Promise<TrafficSourcesResponse>;
58
+ };
59
+ control: {
60
+ /** Idempotent on `externalId`. `orgKey` comes back only on first creation. */
61
+ createOrganization(input: CreateOrganizationInput, auth: PlatformAuth, init?: DataRequestInit): Promise<CreateOrganizationResponse>;
62
+ /** Issues a new key and revokes every previous one. The recovery path for a lost key. */
63
+ rotateOrgKey(organizationId: string, auth: PlatformAuth, init?: DataRequestInit): Promise<RotateOrganizationKeyResponse>;
64
+ updateOrganizationQuota(organizationId: string, input: UpdateOrganizationQuotaInput, auth: PlatformAuth, init?: DataRequestInit): Promise<UpdateOrganizationQuotaResponse>;
65
+ /** Idempotent on `externalId`. `clientSecret` comes back only on first creation. */
66
+ createProject(input: CreateProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<CreateProjectResponse>;
67
+ rotateServerClientSecret(projectId: string, clientId: string, auth: OrganizationAuth, init?: DataRequestInit): Promise<RotateClientSecretResponse>;
68
+ /** Irreversible. Idempotent: a project that is already gone still answers 202. */
69
+ deleteProject(projectId: string, input: DeleteProjectInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<DeleteProjectResponse>;
70
+ /** Idempotent: a repeat with the same body changes nothing and answers 200. */
71
+ upsertEventMeta(projectId: string, name: string, input: UpsertEventMetaInput, auth: OrganizationAuth, init?: DataRequestInit): Promise<EventMetaResponse>;
72
+ };
88
73
  }
89
74
  declare function createDataClient(options: DataClientOptions): DataClient;
90
-
91
- export { type DataClient, type DataClientOptions, type DataClientRetryOptions, type DataRequestInit, type OrganizationAuth, type PlatformAuth, createDataClient };
75
+ //#endregion
76
+ export { DataClient, DataClientOptions, DataClientRetryOptions, DataRequestInit, OrganizationAuth, PlatformAuth, createDataClient };
77
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;UAkEiB;;EAEf;;EAEA;;EAEA;;EAEA;;UAGe,0BAA0B;;EAEzC;;EAEA,eAAe,WAAW;;EAE1B;EACA,QAAQ;;EAER;;UAGe;EACf,SAAS;;;;;;;;;UAUM;EACf;;UAGe;EACf;;UAGe;EACf;;;;;;IAME,MAAM,QAAQ,wBAAwB,OAAO,kBAAkB,QAAQ;;EAEzE;IACE,iBAAiB,OAAO,uBAAuB,OAAO,kBAAkB,QAAQ;IAChF,OAAO,OAAO,aAAa,OAAO,kBAAkB,QAAQ;IAC5D,UAAU,OAAO,gBAAgB,OAAO,kBAAkB,QAAQ;IAClE,gBAAgB,OAAO,sBAAsB,OAAO,kBAAkB,QAAQ;IAC9E,eAAe,OAAO,qBAAqB,OAAO,kBAAkB,QAAQ;;EAE9E;;IAEE,mBACE,OAAO,yBACP,MAAM,cACN,OAAO,kBACN,QAAQ;;IAEX,aACE,wBACA,MAAM,cACN,OAAO,kBACN,QAAQ;IACX,wBACE,wBACA,OAAO,8BACP,MAAM,cACN,OAAO,kBACN,QAAQ;;IAEX,cACE,OAAO,oBACP,MAAM,kBACN,OAAO,kBACN,QAAQ;IACX,yBACE,mBACA,kBACA,MAAM,kBACN,OAAO,kBACN,QAAQ;;IAEX,cACE,mBACA,OAAO,oBACP,MAAM,kBACN,OAAO,kBACN,QAAQ;;IAEX,gBACE,mBACA,cACA,OAAO,sBACP,MAAM,kBACN,OAAO,kBACN,QAAQ;;;iBA0GC,iBAAiB,SAAS,oBAAoB"}