@pontive/server 1.23.1 → 1.24.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 (48) hide show
  1. package/README.md +42 -0
  2. package/dist/authorization.cjs +1 -1
  3. package/dist/authorization.js +2 -2
  4. package/dist/client-BiVX0Gh-.cjs +2 -0
  5. package/dist/client-BiVX0Gh-.cjs.map +1 -0
  6. package/dist/client-_s4seciG.js +6693 -0
  7. package/dist/client-_s4seciG.js.map +1 -0
  8. package/dist/env.d.cts +2 -0
  9. package/dist/env.d.ts +2 -0
  10. package/dist/index.cjs +4 -4
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +4 -0
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.js +219 -248
  15. package/dist/index.js.map +1 -1
  16. package/dist/management/client.d.cts +68 -0
  17. package/dist/management/client.d.ts +68 -0
  18. package/dist/management/core.d.cts +112 -0
  19. package/dist/management/core.d.ts +112 -0
  20. package/dist/management/errors.d.cts +78 -0
  21. package/dist/management/errors.d.ts +78 -0
  22. package/dist/management/generated/namespaces.d.cts +5404 -0
  23. package/dist/management/generated/namespaces.d.ts +5404 -0
  24. package/dist/management/generated/types.d.cts +7756 -0
  25. package/dist/management/generated/types.d.ts +7756 -0
  26. package/dist/management/index.d.cts +10 -0
  27. package/dist/management/index.d.ts +10 -0
  28. package/dist/management-credential--CmS8XaV.cjs +2 -0
  29. package/dist/management-credential--CmS8XaV.cjs.map +1 -0
  30. package/dist/management-credential-CynS93TR.js +166 -0
  31. package/dist/management-credential-CynS93TR.js.map +1 -0
  32. package/dist/management.cjs +2 -0
  33. package/dist/management.cjs.map +1 -0
  34. package/dist/management.js +20 -0
  35. package/dist/management.js.map +1 -0
  36. package/dist/resource-server.cjs +1 -1
  37. package/dist/resource-server.cjs.map +1 -1
  38. package/dist/resource-server.js +3 -4
  39. package/dist/resource-server.js.map +1 -1
  40. package/package.json +12 -2
  41. package/dist/management-credential-BNyhHagG.cjs +0 -2
  42. package/dist/management-credential-BNyhHagG.cjs.map +0 -1
  43. package/dist/management-credential-VhmMzGDl.js +0 -39
  44. package/dist/management-credential-VhmMzGDl.js.map +0 -1
  45. package/dist/oidc--We55Nrh.cjs +0 -2
  46. package/dist/oidc--We55Nrh.cjs.map +0 -1
  47. package/dist/oidc-CB0FqjFz.js +0 -131
  48. package/dist/oidc-CB0FqjFz.js.map +0 -1
@@ -0,0 +1,68 @@
1
+ import { Env } from '../env.js';
2
+ import { PontiveNamespaces } from './generated/namespaces.js';
3
+ /**
4
+ * How a {@link Pontive} client authenticates and where it sends its calls.
5
+ * Every field is optional: one left out falls back to its environment
6
+ * variable, so `new Pontive()` works with `PONTIVE_SECRET_KEY` set.
7
+ */
8
+ export interface PontiveOptions {
9
+ /** The instance's secret key, `pontive_sk_…`. Default: `PONTIVE_SECRET_KEY`. */
10
+ secretKey?: string;
11
+ /**
12
+ * A bearer token, or a function returning one, for a caller that manages
13
+ * its own: a management token, or a user's me token for `pontive.me`.
14
+ */
15
+ token?: string | (() => string | Promise<string>);
16
+ /** A service account's client id; with `clientSecret`, exchanged at `issuer` for a management token. */
17
+ clientId?: string;
18
+ /** A service account's client secret. */
19
+ clientSecret?: string;
20
+ /**
21
+ * The instance's issuer: where client credentials are exchanged, and the
22
+ * auth domain that serves `pontive.me` (the signed-in user's own routes,
23
+ * called with that user's me token). Default: `PONTIVE_ISSUER`.
24
+ */
25
+ issuer?: string;
26
+ /**
27
+ * The instance's region (`us`, `eu`, `au`): it picks `api.{region}.pontive.com`
28
+ * and its `authz.` and `ingest.` hosts. Default: the region a secret key
29
+ * names, then `PONTIVE_REGION`, then the region in the issuer's host.
30
+ */
31
+ region?: string;
32
+ /** Overrides the management API's base, for a proxy or a non-production Pontive. Default: `PONTIVE_MANAGEMENT_URL`. */
33
+ managementUrl?: string;
34
+ /** Overrides the authorization host. Default: `managementUrl` with its `api.` label replaced by `authz.`. */
35
+ authzUrl?: string;
36
+ /** Overrides the usage ingestion host. Default: `managementUrl` with its `api.` label replaced by `ingest.`. */
37
+ ingestUrl?: string;
38
+ /** Sent as `X-Pontive-Instance-ID`; a secret key names its own instance and needs none. Default: `PONTIVE_INSTANCE_ID`. */
39
+ instanceId?: string;
40
+ /** How many times a failed call is retried: a 429, a 5xx or a network error, when it is safe to repeat. Default 2. */
41
+ maxRetries?: number;
42
+ /** Milliseconds each attempt may take. Default 60000. */
43
+ timeout?: number;
44
+ /** The `fetch` to send with. Default: the global one. */
45
+ fetch?: typeof fetch;
46
+ /** The environment to fall back to. Default: `process.env`. */
47
+ env?: Env;
48
+ }
49
+ /** The region a secret key names: `pontive_sk_live_us_…` → `us`. */
50
+ export declare function secretKeyRegion(key: string): string | undefined;
51
+ /**
52
+ * A client for Pontive's management API, and its authorization and usage
53
+ * ingestion hosts. Namespaces follow the API: `pontive.users`,
54
+ * `pontive.organizations`, `pontive.billing.invoices`, …; method names follow
55
+ * its operation ids.
56
+ *
57
+ * ```ts
58
+ * const pontive = new Pontive({ secretKey: process.env.PONTIVE_SECRET_KEY });
59
+ * const user = await pontive.users.get("usr_…");
60
+ * for await (const org of pontive.organizations.list()) console.log(org.name);
61
+ * ```
62
+ *
63
+ * Server-side only: a secret key or client secret never belongs in a browser,
64
+ * and the constructor refuses one there.
65
+ */
66
+ export declare class Pontive extends PontiveNamespaces {
67
+ constructor(options?: PontiveOptions);
68
+ }
@@ -0,0 +1,112 @@
1
+ /** The host an operation is served on: api.{region}, authz.{region}, ingest.{region}, or the instance's auth domain (`/v1/me`). */
2
+ export type Host = "api" | "authz" | "ingest" | "auth";
3
+ /** One call, as a generated method describes it. */
4
+ export interface APIRequest {
5
+ host: Host;
6
+ method: string;
7
+ path: string;
8
+ query?: object;
9
+ headers?: Record<string, string | undefined>;
10
+ body?: unknown;
11
+ /** The operation takes `X-Idempotency-Key`. */
12
+ idempotent?: boolean;
13
+ /** The result is a file, not JSON. */
14
+ binary?: boolean;
15
+ }
16
+ /** Options for one call. */
17
+ export interface RequestOptions {
18
+ /**
19
+ * The call's `X-Idempotency-Key`. Operations that take one get a random key
20
+ * by default, the same across the call's retries; set your own to make a
21
+ * call safe to repeat across processes.
22
+ */
23
+ idempotencyKey?: string;
24
+ /** Extra headers. */
25
+ headers?: Record<string, string>;
26
+ /** How many times the call is retried; `0` turns retries off. */
27
+ maxRetries?: number;
28
+ /** Milliseconds each attempt may take. */
29
+ timeout?: number;
30
+ /** Aborts the call. */
31
+ signal?: AbortSignal;
32
+ }
33
+ export interface CoreConfig {
34
+ hosts: Record<Host, string>;
35
+ token: () => Promise<string>;
36
+ /** Drops a cached token the API refused; true when a new one can be had. */
37
+ invalidate: () => boolean;
38
+ instanceId?: string;
39
+ maxRetries: number;
40
+ timeout: number;
41
+ fetch: typeof fetch;
42
+ /** Tests replace the waits between retries. */
43
+ sleep?: (ms: number) => Promise<void>;
44
+ }
45
+ /** The request engine every generated method calls. */
46
+ export declare class Core {
47
+ private readonly config;
48
+ constructor(config: CoreConfig);
49
+ request<T>(req: APIRequest, options?: RequestOptions): APIPromise<T>;
50
+ page<Item, Body>(kind: "page" | "cursor", req: APIRequest, options?: RequestOptions): PagePromise<Item, Body>;
51
+ private send;
52
+ }
53
+ /** Honours Retry-After (seconds or an HTTP date, at most a minute), else 0.5s doubling, at most 8s, with jitter. */
54
+ export declare function backoff(attempt: number, headers?: Headers): number;
55
+ /**
56
+ * The result of a call: await it for the decoded body, or call
57
+ * `withResponse()` for the body and the `Response`, to read a header such as
58
+ * the `ETag` an `If-Match` update needs.
59
+ */
60
+ export declare class APIPromise<T> implements PromiseLike<T> {
61
+ private readonly result;
62
+ constructor(result: Promise<{
63
+ data: T;
64
+ response: Response;
65
+ }>);
66
+ /** The decoded body and the HTTP response. */
67
+ withResponse(): Promise<{
68
+ data: T;
69
+ response: Response;
70
+ }>;
71
+ then<A = T, B = never>(onfulfilled?: ((value: T) => A | PromiseLike<A>) | null, onrejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<A | B>;
72
+ catch<B = never>(onrejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<T | B>;
73
+ finally(onfinally?: (() => void) | null): Promise<T>;
74
+ }
75
+ /** A page of a list, and the way to the next one. */
76
+ export declare class Page<Item, Body> implements AsyncIterable<Item> {
77
+ private readonly kind;
78
+ /** The response body as the API sent it, with its pagination. */
79
+ readonly body: Body;
80
+ private readonly query;
81
+ private readonly load;
82
+ /** This page's items. */
83
+ readonly data: Item[];
84
+ constructor(kind: "page" | "cursor",
85
+ /** The response body as the API sent it, with its pagination. */
86
+ body: Body, query: object | undefined, load: (query: object) => PagePromise<Item, Body>);
87
+ /** Whether there is a page after this one. */
88
+ hasNextPage(): boolean;
89
+ /** The next page; call only when `hasNextPage()`. */
90
+ nextPage(): PagePromise<Item, Body>;
91
+ /** Every item from this page on, fetching the next pages as it goes. */
92
+ [Symbol.asyncIterator](): AsyncIterator<Item>;
93
+ }
94
+ /**
95
+ * A list call: await it for the first `Page`, or iterate it with
96
+ * `for await (const item of …)` for every item across pages.
97
+ */
98
+ export declare class PagePromise<Item, Body> extends APIPromise<Page<Item, Body>> implements AsyncIterable<Item> {
99
+ [Symbol.asyncIterator](): AsyncIterator<Item>;
100
+ }
101
+ /** A token for a credential: as it is, from the caller's function, or exchanged for client credentials. */
102
+ export declare function tokenSource(input: {
103
+ token?: string | (() => string | Promise<string>);
104
+ clientId?: string;
105
+ clientSecret?: string;
106
+ issuer?: string;
107
+ audience: string;
108
+ fetch: typeof fetch;
109
+ }): {
110
+ token: () => Promise<string>;
111
+ invalidate: () => boolean;
112
+ };
@@ -0,0 +1,112 @@
1
+ /** The host an operation is served on: api.{region}, authz.{region}, ingest.{region}, or the instance's auth domain (`/v1/me`). */
2
+ export type Host = "api" | "authz" | "ingest" | "auth";
3
+ /** One call, as a generated method describes it. */
4
+ export interface APIRequest {
5
+ host: Host;
6
+ method: string;
7
+ path: string;
8
+ query?: object;
9
+ headers?: Record<string, string | undefined>;
10
+ body?: unknown;
11
+ /** The operation takes `X-Idempotency-Key`. */
12
+ idempotent?: boolean;
13
+ /** The result is a file, not JSON. */
14
+ binary?: boolean;
15
+ }
16
+ /** Options for one call. */
17
+ export interface RequestOptions {
18
+ /**
19
+ * The call's `X-Idempotency-Key`. Operations that take one get a random key
20
+ * by default, the same across the call's retries; set your own to make a
21
+ * call safe to repeat across processes.
22
+ */
23
+ idempotencyKey?: string;
24
+ /** Extra headers. */
25
+ headers?: Record<string, string>;
26
+ /** How many times the call is retried; `0` turns retries off. */
27
+ maxRetries?: number;
28
+ /** Milliseconds each attempt may take. */
29
+ timeout?: number;
30
+ /** Aborts the call. */
31
+ signal?: AbortSignal;
32
+ }
33
+ export interface CoreConfig {
34
+ hosts: Record<Host, string>;
35
+ token: () => Promise<string>;
36
+ /** Drops a cached token the API refused; true when a new one can be had. */
37
+ invalidate: () => boolean;
38
+ instanceId?: string;
39
+ maxRetries: number;
40
+ timeout: number;
41
+ fetch: typeof fetch;
42
+ /** Tests replace the waits between retries. */
43
+ sleep?: (ms: number) => Promise<void>;
44
+ }
45
+ /** The request engine every generated method calls. */
46
+ export declare class Core {
47
+ private readonly config;
48
+ constructor(config: CoreConfig);
49
+ request<T>(req: APIRequest, options?: RequestOptions): APIPromise<T>;
50
+ page<Item, Body>(kind: "page" | "cursor", req: APIRequest, options?: RequestOptions): PagePromise<Item, Body>;
51
+ private send;
52
+ }
53
+ /** Honours Retry-After (seconds or an HTTP date, at most a minute), else 0.5s doubling, at most 8s, with jitter. */
54
+ export declare function backoff(attempt: number, headers?: Headers): number;
55
+ /**
56
+ * The result of a call: await it for the decoded body, or call
57
+ * `withResponse()` for the body and the `Response`, to read a header such as
58
+ * the `ETag` an `If-Match` update needs.
59
+ */
60
+ export declare class APIPromise<T> implements PromiseLike<T> {
61
+ private readonly result;
62
+ constructor(result: Promise<{
63
+ data: T;
64
+ response: Response;
65
+ }>);
66
+ /** The decoded body and the HTTP response. */
67
+ withResponse(): Promise<{
68
+ data: T;
69
+ response: Response;
70
+ }>;
71
+ then<A = T, B = never>(onfulfilled?: ((value: T) => A | PromiseLike<A>) | null, onrejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<A | B>;
72
+ catch<B = never>(onrejected?: ((reason: unknown) => B | PromiseLike<B>) | null): Promise<T | B>;
73
+ finally(onfinally?: (() => void) | null): Promise<T>;
74
+ }
75
+ /** A page of a list, and the way to the next one. */
76
+ export declare class Page<Item, Body> implements AsyncIterable<Item> {
77
+ private readonly kind;
78
+ /** The response body as the API sent it, with its pagination. */
79
+ readonly body: Body;
80
+ private readonly query;
81
+ private readonly load;
82
+ /** This page's items. */
83
+ readonly data: Item[];
84
+ constructor(kind: "page" | "cursor",
85
+ /** The response body as the API sent it, with its pagination. */
86
+ body: Body, query: object | undefined, load: (query: object) => PagePromise<Item, Body>);
87
+ /** Whether there is a page after this one. */
88
+ hasNextPage(): boolean;
89
+ /** The next page; call only when `hasNextPage()`. */
90
+ nextPage(): PagePromise<Item, Body>;
91
+ /** Every item from this page on, fetching the next pages as it goes. */
92
+ [Symbol.asyncIterator](): AsyncIterator<Item>;
93
+ }
94
+ /**
95
+ * A list call: await it for the first `Page`, or iterate it with
96
+ * `for await (const item of …)` for every item across pages.
97
+ */
98
+ export declare class PagePromise<Item, Body> extends APIPromise<Page<Item, Body>> implements AsyncIterable<Item> {
99
+ [Symbol.asyncIterator](): AsyncIterator<Item>;
100
+ }
101
+ /** A token for a credential: as it is, from the caller's function, or exchanged for client credentials. */
102
+ export declare function tokenSource(input: {
103
+ token?: string | (() => string | Promise<string>);
104
+ clientId?: string;
105
+ clientSecret?: string;
106
+ issuer?: string;
107
+ audience: string;
108
+ fetch: typeof fetch;
109
+ }): {
110
+ token: () => Promise<string>;
111
+ invalidate: () => boolean;
112
+ };
@@ -0,0 +1,78 @@
1
+ /** One per-field finding of a refusal. */
2
+ export interface ErrorDetail {
3
+ field?: string;
4
+ code?: string;
5
+ message?: string;
6
+ path?: string;
7
+ [key: string]: unknown;
8
+ }
9
+ /**
10
+ * A refusal from the management API: a non-2xx answer, with the API's error
11
+ * envelope. Each status has its own subclass (`NotFoundError`,
12
+ * `RateLimitError`, …); read `code` for the precise reason.
13
+ *
14
+ * ```ts
15
+ * try {
16
+ * await pontive.organizations.createMember(org, { user_id });
17
+ * } catch (err) {
18
+ * if (err instanceof PontiveAPIError && err.code === "seat_limit_reached") { … }
19
+ * else throw err;
20
+ * }
21
+ * ```
22
+ */
23
+ export declare class PontiveAPIError extends Error {
24
+ /** The HTTP status. */
25
+ readonly status: number;
26
+ /** The category: validation_error, authentication_error, authorization_error, not_found, conflict_error, rate_limit_error or internal_error. */
27
+ readonly type?: string;
28
+ /** The machine-readable reason, such as `permission_denied` or `seat_limit_reached`. */
29
+ readonly code?: string;
30
+ /** The request parameter the error is about, when there is one. */
31
+ readonly param?: string;
32
+ /** Documentation about the error, when there is some. */
33
+ readonly docUrl?: string;
34
+ /** Per-field findings, on a refusal that has them. */
35
+ readonly details: ErrorDetail[];
36
+ /** The `X-Request-ID` the API answered with; quote it to support. */
37
+ readonly requestId?: string;
38
+ /** The response's headers. */
39
+ readonly headers: Headers;
40
+ /** The response body as it came (parsed JSON, or text). */
41
+ readonly body: unknown;
42
+ constructor(status: number, headers: Headers, body: unknown);
43
+ /** The error for a status: its subclass where it has one. */
44
+ static from(status: number, headers: Headers, body: unknown): PontiveAPIError;
45
+ }
46
+ /** 400 */
47
+ export declare class BadRequestError extends PontiveAPIError {
48
+ }
49
+ /** 401: the credential is missing, wrong, expired or for another API. */
50
+ export declare class AuthenticationError extends PontiveAPIError {
51
+ }
52
+ /** 403: the credential may not do this. */
53
+ export declare class PermissionDeniedError extends PontiveAPIError {
54
+ }
55
+ /** 404 */
56
+ export declare class NotFoundError extends PontiveAPIError {
57
+ }
58
+ /** 409 */
59
+ export declare class ConflictError extends PontiveAPIError {
60
+ }
61
+ /** 412: an `If-Match` that no longer matches. */
62
+ export declare class PreconditionFailedError extends PontiveAPIError {
63
+ }
64
+ /** 422: the request is understood but invalid; `details` says where. */
65
+ export declare class UnprocessableEntityError extends PontiveAPIError {
66
+ }
67
+ /** 429: retried automatically first; this is what is left after the retries. */
68
+ export declare class RateLimitError extends PontiveAPIError {
69
+ }
70
+ /** 5xx */
71
+ export declare class InternalServerError extends PontiveAPIError {
72
+ }
73
+ /** A call that got no answer: a network failure, a timeout or an abort. */
74
+ export declare class PontiveConnectionError extends Error {
75
+ constructor(message: string, options?: {
76
+ cause?: unknown;
77
+ });
78
+ }
@@ -0,0 +1,78 @@
1
+ /** One per-field finding of a refusal. */
2
+ export interface ErrorDetail {
3
+ field?: string;
4
+ code?: string;
5
+ message?: string;
6
+ path?: string;
7
+ [key: string]: unknown;
8
+ }
9
+ /**
10
+ * A refusal from the management API: a non-2xx answer, with the API's error
11
+ * envelope. Each status has its own subclass (`NotFoundError`,
12
+ * `RateLimitError`, …); read `code` for the precise reason.
13
+ *
14
+ * ```ts
15
+ * try {
16
+ * await pontive.organizations.createMember(org, { user_id });
17
+ * } catch (err) {
18
+ * if (err instanceof PontiveAPIError && err.code === "seat_limit_reached") { … }
19
+ * else throw err;
20
+ * }
21
+ * ```
22
+ */
23
+ export declare class PontiveAPIError extends Error {
24
+ /** The HTTP status. */
25
+ readonly status: number;
26
+ /** The category: validation_error, authentication_error, authorization_error, not_found, conflict_error, rate_limit_error or internal_error. */
27
+ readonly type?: string;
28
+ /** The machine-readable reason, such as `permission_denied` or `seat_limit_reached`. */
29
+ readonly code?: string;
30
+ /** The request parameter the error is about, when there is one. */
31
+ readonly param?: string;
32
+ /** Documentation about the error, when there is some. */
33
+ readonly docUrl?: string;
34
+ /** Per-field findings, on a refusal that has them. */
35
+ readonly details: ErrorDetail[];
36
+ /** The `X-Request-ID` the API answered with; quote it to support. */
37
+ readonly requestId?: string;
38
+ /** The response's headers. */
39
+ readonly headers: Headers;
40
+ /** The response body as it came (parsed JSON, or text). */
41
+ readonly body: unknown;
42
+ constructor(status: number, headers: Headers, body: unknown);
43
+ /** The error for a status: its subclass where it has one. */
44
+ static from(status: number, headers: Headers, body: unknown): PontiveAPIError;
45
+ }
46
+ /** 400 */
47
+ export declare class BadRequestError extends PontiveAPIError {
48
+ }
49
+ /** 401: the credential is missing, wrong, expired or for another API. */
50
+ export declare class AuthenticationError extends PontiveAPIError {
51
+ }
52
+ /** 403: the credential may not do this. */
53
+ export declare class PermissionDeniedError extends PontiveAPIError {
54
+ }
55
+ /** 404 */
56
+ export declare class NotFoundError extends PontiveAPIError {
57
+ }
58
+ /** 409 */
59
+ export declare class ConflictError extends PontiveAPIError {
60
+ }
61
+ /** 412: an `If-Match` that no longer matches. */
62
+ export declare class PreconditionFailedError extends PontiveAPIError {
63
+ }
64
+ /** 422: the request is understood but invalid; `details` says where. */
65
+ export declare class UnprocessableEntityError extends PontiveAPIError {
66
+ }
67
+ /** 429: retried automatically first; this is what is left after the retries. */
68
+ export declare class RateLimitError extends PontiveAPIError {
69
+ }
70
+ /** 5xx */
71
+ export declare class InternalServerError extends PontiveAPIError {
72
+ }
73
+ /** A call that got no answer: a network failure, a timeout or an abort. */
74
+ export declare class PontiveConnectionError extends Error {
75
+ constructor(message: string, options?: {
76
+ cause?: unknown;
77
+ });
78
+ }