@atlasauth/backend 0.4.0 → 0.6.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 (119) hide show
  1. package/README.md +187 -0
  2. package/dist/client/activity.d.ts +104 -0
  3. package/dist/client/activity.js +29 -0
  4. package/dist/client/activity.js.map +1 -0
  5. package/dist/client/audit-events.d.ts +103 -0
  6. package/dist/client/audit-events.js +43 -0
  7. package/dist/client/audit-events.js.map +1 -0
  8. package/dist/client/billing-plans.d.ts +43 -0
  9. package/dist/client/billing-plans.js +26 -0
  10. package/dist/client/billing-plans.js.map +1 -1
  11. package/dist/client/connectors.d.ts +174 -0
  12. package/dist/client/connectors.js +54 -0
  13. package/dist/client/connectors.js.map +1 -0
  14. package/dist/client/data-subject-requests.d.ts +21 -0
  15. package/dist/client/data-subject-requests.js +15 -0
  16. package/dist/client/data-subject-requests.js.map +1 -1
  17. package/dist/client/design.d.ts +295 -0
  18. package/dist/client/design.js +76 -0
  19. package/dist/client/design.js.map +1 -0
  20. package/dist/client/diagnostics.d.ts +53 -0
  21. package/dist/client/diagnostics.js +24 -0
  22. package/dist/client/diagnostics.js.map +1 -0
  23. package/dist/client/email-addresses.d.ts +22 -0
  24. package/dist/client/email-addresses.js +17 -0
  25. package/dist/client/email-addresses.js.map +1 -0
  26. package/dist/client/entitlement-overrides.d.ts +50 -0
  27. package/dist/client/entitlement-overrides.js +20 -0
  28. package/dist/client/entitlement-overrides.js.map +1 -0
  29. package/dist/client/error.d.ts +28 -0
  30. package/dist/client/error.js +27 -1
  31. package/dist/client/error.js.map +1 -1
  32. package/dist/client/index.d.ts +458 -16
  33. package/dist/client/index.js +76 -2
  34. package/dist/client/index.js.map +1 -1
  35. package/dist/client/instance.d.ts +54 -0
  36. package/dist/client/instance.js +18 -0
  37. package/dist/client/instance.js.map +1 -1
  38. package/dist/client/invitations.d.ts +14 -0
  39. package/dist/client/invitations.js +9 -0
  40. package/dist/client/invitations.js.map +1 -1
  41. package/dist/client/legacy-auth.d.ts +45 -0
  42. package/dist/client/legacy-auth.js +18 -0
  43. package/dist/client/legacy-auth.js.map +1 -0
  44. package/dist/client/mcp.d.ts +86 -0
  45. package/dist/client/mcp.js +47 -0
  46. package/dist/client/mcp.js.map +1 -0
  47. package/dist/client/notifications.d.ts +92 -0
  48. package/dist/client/notifications.js +55 -0
  49. package/dist/client/notifications.js.map +1 -0
  50. package/dist/client/oauth-clients.d.ts +46 -2
  51. package/dist/client/oauth-clients.js +4 -0
  52. package/dist/client/oauth-clients.js.map +1 -1
  53. package/dist/client/oauth-providers.d.ts +67 -7
  54. package/dist/client/oauth-providers.js +7 -2
  55. package/dist/client/oauth-providers.js.map +1 -1
  56. package/dist/client/openfga.d.ts +137 -0
  57. package/dist/client/openfga.js +72 -0
  58. package/dist/client/openfga.js.map +1 -0
  59. package/dist/client/org-ldap-connections.d.ts +75 -0
  60. package/dist/client/org-ldap-connections.js +36 -0
  61. package/dist/client/org-ldap-connections.js.map +1 -0
  62. package/dist/client/organization-settings-schema.d.ts +24 -0
  63. package/dist/client/organization-settings-schema.js +30 -0
  64. package/dist/client/organization-settings-schema.js.map +1 -0
  65. package/dist/client/organizations.d.ts +205 -4
  66. package/dist/client/organizations.js +109 -0
  67. package/dist/client/organizations.js.map +1 -1
  68. package/dist/client/pca.d.ts +59 -0
  69. package/dist/client/pca.js +40 -0
  70. package/dist/client/pca.js.map +1 -0
  71. package/dist/client/platform.d.ts +328 -0
  72. package/dist/client/platform.js +187 -0
  73. package/dist/client/platform.js.map +1 -0
  74. package/dist/client/redirect-urls.d.ts +23 -0
  75. package/dist/client/redirect-urls.js +22 -0
  76. package/dist/client/redirect-urls.js.map +1 -0
  77. package/dist/client/request.d.ts +45 -0
  78. package/dist/client/request.js +35 -2
  79. package/dist/client/request.js.map +1 -1
  80. package/dist/client/session-exchange-apps.d.ts +43 -0
  81. package/dist/client/session-exchange-apps.js +25 -0
  82. package/dist/client/session-exchange-apps.js.map +1 -0
  83. package/dist/client/sessions.d.ts +12 -0
  84. package/dist/client/sessions.js +10 -0
  85. package/dist/client/sessions.js.map +1 -1
  86. package/dist/client/sign-in-tokens.d.ts +13 -1
  87. package/dist/client/sign-in-tokens.js +11 -0
  88. package/dist/client/sign-in-tokens.js.map +1 -1
  89. package/dist/client/test-mode.d.ts +44 -0
  90. package/dist/client/test-mode.js +26 -0
  91. package/dist/client/test-mode.js.map +1 -0
  92. package/dist/client/tickets.d.ts +49 -0
  93. package/dist/client/tickets.js +19 -0
  94. package/dist/client/tickets.js.map +1 -0
  95. package/dist/client/users.d.ts +346 -0
  96. package/dist/client/users.js +228 -0
  97. package/dist/client/users.js.map +1 -1
  98. package/dist/client/waitlist.d.ts +21 -0
  99. package/dist/client/waitlist.js +16 -0
  100. package/dist/client/waitlist.js.map +1 -1
  101. package/dist/client/webhooks.d.ts +60 -6
  102. package/dist/client/webhooks.js +36 -2
  103. package/dist/client/webhooks.js.map +1 -1
  104. package/dist/discovery.d.ts +49 -0
  105. package/dist/discovery.js +143 -0
  106. package/dist/discovery.js.map +1 -0
  107. package/dist/index.d.ts +3 -0
  108. package/dist/index.js +15 -1
  109. package/dist/index.js.map +1 -1
  110. package/dist/jwks-cache.d.ts +8 -0
  111. package/dist/jwks-cache.js +20 -3
  112. package/dist/jwks-cache.js.map +1 -1
  113. package/dist/logout-token.d.ts +97 -0
  114. package/dist/logout-token.js +182 -0
  115. package/dist/logout-token.js.map +1 -0
  116. package/dist/verify.d.ts +26 -3
  117. package/dist/verify.js +40 -5
  118. package/dist/verify.js.map +1 -1
  119. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # @atlasauth/backend
2
+
3
+ Server-side Atlas for Node, Deno, Bun and edge runtimes. It does three things:
4
+
5
+ - verifies Atlas session tokens, webhooks and back-channel logout tokens
6
+ - gives you a typed client for the Backend API, using your secret key (`sk_...`)
7
+ - gives you a typed client for the Platform API, using your platform key (`psk_...`)
8
+
9
+ It needs nothing but `fetch`.
10
+
11
+ ```sh
12
+ npm install @atlasauth/backend
13
+ ```
14
+
15
+ ## Verify a session
16
+
17
+ ```ts
18
+ import { AtlasBackend } from '@atlasauth/backend';
19
+
20
+ const atlas = new AtlasBackend({ issuer: 'https://clerk.example.com' });
21
+ const result = await atlas.verify(sessionToken);
22
+ if (result.ok) console.log(result.claims.sub);
23
+ ```
24
+
25
+ The JWKS is found from the issuer and cached. Instances on the shared host also pass `instanceId` (or `publishableKey`).
26
+
27
+ ## Management client (secret key)
28
+
29
+ ```ts
30
+ import { createAtlasClient, paginate } from '@atlasauth/backend';
31
+
32
+ const atlas = createAtlasClient({ secretKey: process.env.ATLAS_SECRET_KEY! });
33
+
34
+ const user = await atlas.users.create({ email_address: 'ada@example.com' });
35
+ for await (const u of paginate(atlas.users.list)) console.log(u.id);
36
+ ```
37
+
38
+ Every Backend API operation has a method, grouped by resource. The groups are:
39
+
40
+ | Area | Namespaces |
41
+ | --- | --- |
42
+ | Users and sessions | `users`, `emailAddresses`, `sessions`, `signInTokens`, `actorTokens` |
43
+ | Organizations | `organizations`, `invitations` |
44
+ | Roles and authorization | `roles`, `permissions`, `fga`, `openfga` |
45
+ | Access and sign-up control | `waitlist`, `allowlist`, `blocklist`, `domains`, `redirectUrls` |
46
+ | Instance settings | `instance`, `instanceSecurity`, `design`, `branding`, `localizations` |
47
+ | Templates and messaging | `emailTemplates`, `smsTemplates`, `messaging`, `notifications` |
48
+ | Social and enterprise sign-in | `oauthProviders`, `connectors`, `ssoConnections`, `ssoOnboarding`, `orgLdapConnections`, `scimTokens`, `scimProvisioning`, `legacyAuthConnection` |
49
+ | OAuth and tokens | `oauthClients`, `resourceServers`, `jwtTemplates`, `apiKeys`, `machines`, `tokens`, `sessionExchangeApps`, `tickets` |
50
+ | Webhooks and audit | `webhooks`, `auditLogs`, `auditEvents`, `events`, `usage`, `configChangelog`, `logStreams` |
51
+ | Security | `attackProtection`, `rateLimitPolicy`, `riskBasedMfa`, `botSignals`, `captcha`, `networkAcls`, `managedWaf`, `radiusClients` |
52
+ | Billing and entitlements | `billing`, `entitlementOverrides`, `organizationSettingsSchema` |
53
+ | Privacy | `dataSubjectRequests`, `importExport` |
54
+ | Agents and integrations | `actions`, `pca`, `mcp`, `mcpConnector`, `ltiPlatforms` |
55
+ | Development tools | `testMode`, `diagnostics` |
56
+
57
+ ### Check your setup
58
+
59
+ ```ts
60
+ const report = await atlas.instance.preflight();
61
+ for (const f of report.findings) console.log(f.severity, f.message, '→', f.fix);
62
+ ```
63
+
64
+ ### Design the sign-in page
65
+
66
+ ```ts
67
+ import { readFile } from 'node:fs/promises';
68
+
69
+ const logo = await atlas.design.assets.upload(await readFile('logo.png'), {
70
+ kind: 'logo',
71
+ contentType: 'image/png',
72
+ });
73
+ await atlas.design.update({
74
+ palette: { primary: '#4f46e5' },
75
+ logo: { assetId: logo.asset_id },
76
+ });
77
+ // Per-organization override; null removes a setting.
78
+ await atlas.design.organizations.update('org_123', { palette: { primary: null } });
79
+ ```
80
+
81
+ Uploads send the raw image bytes with their content type. A `Blob` brings its own type.
82
+
83
+ ### Strict request bodies
84
+
85
+ By default Atlas ignores a body field an endpoint does not accept. It lists the ignored fields in the `Atlas-Unknown-Fields` response header.
86
+
87
+ ```ts
88
+ const atlas = createAtlasClient({
89
+ secretKey,
90
+ strict: true, // refuse unknown fields with 422 UNKNOWN_FIELD instead
91
+ onUnknownFields: ({ method, path, fields }) => console.warn(method, path, 'ignored', fields),
92
+ });
93
+
94
+ // Override for some calls:
95
+ await atlas.withOptions({ strict: false }).users.update('user_123', body);
96
+ ```
97
+
98
+ ### Errors
99
+
100
+ Every failed call throws `AtlasApiError`, which has `status`, `code` and the full `errors` list. `AtlasErrorCodes` names the codes worth branching on:
101
+
102
+ ```ts
103
+ import { AtlasApiError, AtlasErrorCodes } from '@atlasauth/backend';
104
+
105
+ try {
106
+ await atlas.notifications.send(body);
107
+ } catch (e) {
108
+ if (e instanceof AtlasApiError && e.hasCode(AtlasErrorCodes.EMAIL_DELIVERY_NOT_CONFIGURED)) {
109
+ // set up an email provider first
110
+ }
111
+ }
112
+ ```
113
+
114
+ ## Platform client (platform key)
115
+
116
+ ```ts
117
+ import { createAtlasPlatformClient } from '@atlasauth/backend';
118
+
119
+ const platform = createAtlasPlatformClient({ platformKey: process.env.ATLAS_PLATFORM_KEY! });
120
+
121
+ const app = await platform.apps.create({ name: 'Acme' });
122
+ const signIn = await platform.atlasIdApps.create({
123
+ name: 'Acme',
124
+ redirect_uris: ['https://acme.example/callback'],
125
+ post_logout_redirect_uris: ['https://acme.example/'],
126
+ backchannel_logout_uri: 'https://acme.example/backchannel-logout',
127
+ branding: { theme: 'dark', accent_color: '#4f46e5' },
128
+ });
129
+ console.log(signIn.client_id, signIn.client_secret); // the secret is shown once
130
+ ```
131
+
132
+ The platform client has these namespaces:
133
+
134
+ - `apps`: create, update, archive, transfer, claim and delete apps, manage their instances, rotate and list secrets
135
+ - `accountlessApps`
136
+ - `atlasIdApps`: Sign in with Atlas apps, including design preview and secret rotation
137
+ - `designAssets`
138
+
139
+ It accepts the same `strict`, `onUnknownFields` and `withOptions` settings.
140
+
141
+ ## Back-channel logout
142
+
143
+ When a user signs out of Atlas, Atlas POSTs a `logout_token` to your `backchannel_logout_uri`. Verify it before you end the matching local sessions:
144
+
145
+ ```ts
146
+ import { LogoutTokenVerifier, memoryLogoutReplayStore } from '@atlasauth/backend';
147
+
148
+ const logoutTokens = new LogoutTokenVerifier({
149
+ issuer: 'https://atlasauth.net', // or your instance's issuer
150
+ clientId: process.env.ATLAS_CLIENT_ID!,
151
+ replayStore: memoryLogoutReplayStore(), // use a shared store across processes
152
+ });
153
+
154
+ // Framework-agnostic handler: (form body) -> { status, headers }
155
+ export async function handleBackchannelLogout(form: URLSearchParams) {
156
+ const headers = { 'Cache-Control': 'no-store' };
157
+ const token = form.get('logout_token');
158
+ if (!token) return { status: 400, headers };
159
+
160
+ const result = await logoutTokens.verify(token);
161
+ if (!result.ok) return { status: 400, headers };
162
+
163
+ const { sid, sub } = result.claims;
164
+ if (sid) await sessions.deleteByAtlasSid(sid); // your session store
165
+ else if (sub) await sessions.deleteAllForUser(sub);
166
+ return { status: 200, headers };
167
+ }
168
+ ```
169
+
170
+ The verifier checks the following:
171
+
172
+ - the RS256 signature
173
+ - `iss`, and that `aud` contains your client id
174
+ - `iat`, which must be present, not in the future and not too old, and `exp` if present
175
+ - `jti`
176
+ - the back-channel logout event
177
+ - that `sid` or `sub` is present
178
+ - that there is no `nonce`
179
+ - that `typ` is `logout+jwt`, when the header has one
180
+
181
+ For tokens signed by your own instance, `new AtlasBackend({ issuer }).verifyLogoutToken(token, { clientId })` reuses the instance's cached keys.
182
+
183
+ To refuse replays across several servers, implement `LogoutReplayStore.remember(jti, expiresAtMs)` on a shared store, for example Redis `SET NX PX`.
184
+
185
+ ## Webhooks
186
+
187
+ `verifyWebhook` checks the signature on events Atlas sends to your webhook endpoints. You manage endpoints with `atlas.webhooks.endpoints`: create, update, reveal or rotate a secret, send a test event, and redeliver a past delivery.
@@ -0,0 +1,104 @@
1
+ import { type RequestFn } from './request';
2
+ import type { CursorPage, CursorParams } from './types';
3
+ /** One entry of the product activity feed — the same envelope a webhook carries. */
4
+ export interface ActivityEvent {
5
+ object: 'event';
6
+ id: string;
7
+ type: string;
8
+ payload: {
9
+ id: string;
10
+ type: string;
11
+ /** Emitted (epoch ms). */
12
+ timestamp: number;
13
+ instance_id: string;
14
+ data: unknown;
15
+ };
16
+ /** Occurred (epoch ms). */
17
+ created_at: number;
18
+ }
19
+ export interface ListActivityEventsParams extends CursorParams {
20
+ /** Only this event type, e.g. `user.created`. */
21
+ type?: string;
22
+ /** Lower time bound: epoch ms or an ISO-8601 date. */
23
+ from?: number | string;
24
+ /** Upper time bound: epoch ms or an ISO-8601 date. */
25
+ to?: number | string;
26
+ }
27
+ export interface ActivityEventsPage extends CursorPage<ActivityEvent> {
28
+ object: 'list';
29
+ /** Event types this instance has actually emitted. */
30
+ available_types?: string[];
31
+ }
32
+ export interface UsageMetric {
33
+ metric: string;
34
+ label: string;
35
+ description: string;
36
+ /** False for metrics with no meaningful sum (active users). */
37
+ additive: boolean;
38
+ points: unknown[];
39
+ peak: unknown;
40
+ total: number | null;
41
+ /** Change versus the previous window. */
42
+ trend: number | null;
43
+ }
44
+ export interface UsageReport {
45
+ object: 'usage';
46
+ window: {
47
+ from: string;
48
+ to: string;
49
+ days: number;
50
+ };
51
+ previous_window?: {
52
+ from: string;
53
+ to: string;
54
+ };
55
+ metrics: UsageMetric[];
56
+ monthly_active_users?: {
57
+ value: number | null;
58
+ window_days: number;
59
+ trend: number | null;
60
+ };
61
+ }
62
+ /** One config change: who changed what, when, with a before/after where recorded. */
63
+ export interface ConfigChangelogEntry {
64
+ id: string;
65
+ /** Occurred (epoch ms). */
66
+ at: number;
67
+ actor: {
68
+ type: string;
69
+ id: string | null;
70
+ };
71
+ action: string;
72
+ ip?: string | null;
73
+ changes?: Array<{
74
+ section: string;
75
+ before: unknown;
76
+ after: unknown;
77
+ }>;
78
+ /** Changed field names, when no before/after was recorded. */
79
+ fields?: string[];
80
+ }
81
+ export interface ListConfigChangelogParams extends CursorParams {
82
+ /** Only this config action. */
83
+ action?: string;
84
+ /** Only changes at or after this ISO-8601 date. */
85
+ since?: string;
86
+ }
87
+ export declare function eventsResource(request: RequestFn): {
88
+ /** The activity feed, newest first, cursor-paginated (limit up to 100). */
89
+ list(params?: ListActivityEventsParams): Promise<ActivityEventsPage>;
90
+ };
91
+ export declare function usageResource(request: RequestFn): {
92
+ /** Daily sign-in / active-user series over the last `days`, plus monthly active users. */
93
+ get(params?: {
94
+ days?: number;
95
+ }): Promise<UsageReport>;
96
+ };
97
+ export declare function configChangelogResource(request: RequestFn): {
98
+ list(params?: ListConfigChangelogParams): Promise<{
99
+ object: "config_changelog";
100
+ data: ConfigChangelogEntry[];
101
+ has_more: boolean;
102
+ next_cursor: string | null;
103
+ }>;
104
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.eventsResource = eventsResource;
4
+ exports.usageResource = usageResource;
5
+ exports.configChangelogResource = configChangelogResource;
6
+ function eventsResource(request) {
7
+ return {
8
+ /** The activity feed, newest first, cursor-paginated (limit up to 100). */
9
+ list(params = {}) {
10
+ return request({ method: 'GET', path: '/v1/events', query: { ...params } });
11
+ },
12
+ };
13
+ }
14
+ function usageResource(request) {
15
+ return {
16
+ /** Daily sign-in / active-user series over the last `days`, plus monthly active users. */
17
+ get(params = {}) {
18
+ return request({ method: 'GET', path: '/v1/usage', query: { ...params } });
19
+ },
20
+ };
21
+ }
22
+ function configChangelogResource(request) {
23
+ return {
24
+ list(params = {}) {
25
+ return request({ method: 'GET', path: '/v1/config_changelog', query: { ...params } });
26
+ },
27
+ };
28
+ }
29
+ //# sourceMappingURL=activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.js","sourceRoot":"","sources":["../../src/client/activity.ts"],"names":[],"mappings":";;AA4EA,wCAOC;AAED,sCAOC;AAED,0DAaC;AA/BD,SAAgB,cAAc,CAAC,OAAkB;IAC/C,OAAO;QACL,2EAA2E;QAC3E,IAAI,CAAC,SAAmC,EAAE;YACxC,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QAC9E,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,aAAa,CAAC,OAAkB;IAC9C,OAAO;QACL,0FAA0F;QAC1F,GAAG,CAAC,SAA4B,EAAE;YAChC,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,uBAAuB,CAAC,OAAkB;IACxD,OAAO;QACL,IAAI,CACF,SAAoC,EAAE;YAOtC,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,sBAAsB,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QACxF,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,103 @@
1
+ import { type RequestFn } from './request';
2
+ import type { CursorPage, CursorParams } from './types';
3
+ /**
4
+ * Your OWN audit events — actions in your product you want on an audit trail
5
+ * (e.g. `invoice.sent`). Org-scoped events are streamed to that organization's
6
+ * audit streams. Separate from `auditLogs`, which records what happened in Atlas.
7
+ */
8
+ export interface CustomAuditEvent {
9
+ object: 'audit_event';
10
+ id: string;
11
+ /** The org this event is scoped to, if any. */
12
+ organization_id?: string | null;
13
+ /** Your own actor vocabulary, e.g. `user`, `service`. */
14
+ actor: {
15
+ type?: string;
16
+ id?: string | null;
17
+ };
18
+ /** Your own action string, e.g. `invoice.sent`. */
19
+ action: string;
20
+ target: {
21
+ type?: string | null;
22
+ id?: string | null;
23
+ name?: string | null;
24
+ };
25
+ /** When it happened in your system (epoch ms). */
26
+ occurred_at: number;
27
+ metadata: unknown;
28
+ /** When Atlas received it (epoch ms). */
29
+ created_at: number;
30
+ }
31
+ export interface CreateCustomAuditEventBody {
32
+ actor: {
33
+ type: string;
34
+ id?: string;
35
+ };
36
+ action: string;
37
+ target?: {
38
+ type?: string;
39
+ id?: string;
40
+ name?: string;
41
+ };
42
+ /** Scope to an org (and stream to its SIEM). An unknown org id is a 404. */
43
+ organization_id?: string;
44
+ /** Epoch ms NUMBER; defaults to now. */
45
+ occurred_at?: number;
46
+ /** Non-secret structured context. */
47
+ metadata?: Record<string, unknown>;
48
+ }
49
+ /** Shared filters of the list and export endpoints. */
50
+ export interface CustomAuditEventFilters {
51
+ /** Omit to query across all organizations (a blank value is a 400). */
52
+ organization_id?: string;
53
+ /** One id, or a comma-separated list (matches any). */
54
+ actor_id?: string;
55
+ /** One action, or a comma-separated list. */
56
+ action?: string;
57
+ /** One type, or a comma-separated list. */
58
+ target_type?: string;
59
+ /** One id, or a comma-separated list. */
60
+ target_id?: string;
61
+ /** Inclusive lower bound of occurred_at (epoch ms). */
62
+ from?: number;
63
+ /** Upper bound of occurred_at (epoch ms). */
64
+ to?: number;
65
+ /** OR the actor_id / target_type / target_id filters instead of AND. */
66
+ any_of?: boolean;
67
+ /** Give together with `metadata_value`: match events whose metadata[key] equals the value. */
68
+ metadata_key?: string;
69
+ metadata_value?: string;
70
+ }
71
+ export interface ListCustomAuditEventsParams extends CustomAuditEventFilters, CursorParams {
72
+ }
73
+ export interface ExportCustomAuditEventsParams extends CustomAuditEventFilters {
74
+ /** `jsonl` (default) or `csv`. */
75
+ format?: 'jsonl' | 'csv';
76
+ starting_after?: string;
77
+ }
78
+ export declare function auditEventsResource(request: RequestFn): {
79
+ create(body: CreateCustomAuditEventBody, idempotencyKey?: string): Promise<CustomAuditEvent>;
80
+ /** Up to 100 events, stored atomically (one bad org id fails the whole batch). */
81
+ createBatch(events: CreateCustomAuditEventBody[], idempotencyKey?: string): Promise<{
82
+ object: "list";
83
+ data: CustomAuditEvent[];
84
+ }>;
85
+ /** Newest first, cursor-paginated. */
86
+ list(params?: ListCustomAuditEventsParams): Promise<CursorPage<CustomAuditEvent>>;
87
+ /**
88
+ * Every matching event in one response, as text: JSONL (one event per line;
89
+ * a capped export ends with a `{"truncated":true,…}` line) or CSV.
90
+ */
91
+ export(params?: ExportCustomAuditEventsParams): Promise<string>;
92
+ /**
93
+ * Test-mode reset: delete the custom audit events of a DEVELOPMENT instance,
94
+ * optionally only one org's and/or one action's. A production instance is a 403.
95
+ */
96
+ deleteAll(params?: {
97
+ organization_id?: string;
98
+ action?: string;
99
+ }): Promise<{
100
+ object: "audit_events.bulk_delete";
101
+ deleted: number;
102
+ }>;
103
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.auditEventsResource = auditEventsResource;
4
+ function auditEventsResource(request) {
5
+ return {
6
+ create(body, idempotencyKey) {
7
+ return request({ method: 'POST', path: '/v1/audit_events', body, idempotencyKey });
8
+ },
9
+ /** Up to 100 events, stored atomically (one bad org id fails the whole batch). */
10
+ createBatch(events, idempotencyKey) {
11
+ return request({
12
+ method: 'POST',
13
+ path: '/v1/audit_events/batch',
14
+ body: { events },
15
+ idempotencyKey,
16
+ });
17
+ },
18
+ /** Newest first, cursor-paginated. */
19
+ list(params = {}) {
20
+ return request({ method: 'GET', path: '/v1/audit_events', query: { ...params } });
21
+ },
22
+ /**
23
+ * Every matching event in one response, as text: JSONL (one event per line;
24
+ * a capped export ends with a `{"truncated":true,…}` line) or CSV.
25
+ */
26
+ export(params = {}) {
27
+ return request({
28
+ method: 'GET',
29
+ path: '/v1/audit_events/export',
30
+ query: { ...params },
31
+ raw: true,
32
+ });
33
+ },
34
+ /**
35
+ * Test-mode reset: delete the custom audit events of a DEVELOPMENT instance,
36
+ * optionally only one org's and/or one action's. A production instance is a 403.
37
+ */
38
+ deleteAll(params = {}) {
39
+ return request({ method: 'DELETE', path: '/v1/audit_events', query: { ...params } });
40
+ },
41
+ };
42
+ }
43
+ //# sourceMappingURL=audit-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-events.js","sourceRoot":"","sources":["../../src/client/audit-events.ts"],"names":[],"mappings":";;AAoEA,kDA2CC;AA3CD,SAAgB,mBAAmB,CAAC,OAAkB;IACpD,OAAO;QACL,MAAM,CAAC,IAAgC,EAAE,cAAuB;YAC9D,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QACrF,CAAC;QACD,kFAAkF;QAClF,WAAW,CACT,MAAoC,EACpC,cAAuB;YAEvB,OAAO,OAAO,CAAC;gBACb,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,wBAAwB;gBAC9B,IAAI,EAAE,EAAE,MAAM,EAAE;gBAChB,cAAc;aACf,CAAC,CAAC;QACL,CAAC;QACD,sCAAsC;QACtC,IAAI,CAAC,SAAsC,EAAE;YAC3C,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QACpF,CAAC;QACD;;;WAGG;QACH,MAAM,CAAC,SAAwC,EAAE;YAC/C,OAAO,OAAO,CAAC;gBACb,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,yBAAyB;gBAC/B,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE;gBACpB,GAAG,EAAE,IAAI;aACV,CAAC,CAAC;QACL,CAAC;QACD;;;WAGG;QACH,SAAS,CACP,SAAwD,EAAE;YAE1D,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QACvF,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -67,6 +67,37 @@ export interface ListSubscriptionsParams {
67
67
  subject_type?: string;
68
68
  subject_id?: string;
69
69
  }
70
+ /** Adopt an existing Stripe subscription (same Stripe account) onto an Atlas subject. */
71
+ export interface ImportBillingSubscriptionBody {
72
+ subject_type: 'user' | 'org';
73
+ subject_id: string;
74
+ stripe_subscription_id: string;
75
+ stripe_customer_id?: string;
76
+ /** Resolved from the subscription's price when omitted. */
77
+ plan_id?: string;
78
+ }
79
+ /** Report metered usage for a subject. Idempotent on `idempotency_key`. */
80
+ export interface ReportBillingUsageBody {
81
+ subject_type: 'user' | 'org';
82
+ subject_id: string;
83
+ /** Non-negative. */
84
+ quantity: number;
85
+ idempotency_key: string;
86
+ }
87
+ export interface BillingUsageReport {
88
+ object: 'billing_usage';
89
+ /** False when this `idempotency_key` was already recorded. */
90
+ recorded: boolean;
91
+ /** Whether it was mirrored to a Stripe meter (the plan is metered and configured). */
92
+ metered: boolean;
93
+ total: number;
94
+ }
95
+ export interface BillingSeatSync {
96
+ object: 'billing_seats';
97
+ subject_type: string;
98
+ subject_id: string;
99
+ quantity: number;
100
+ }
70
101
  export declare function billingResource(request: RequestFn): {
71
102
  listPlans(): Promise<ListPage<BillingPlan>>;
72
103
  createPlan(body: CreateBillingPlanBody, idempotencyKey?: string): Promise<BillingPlan>;
@@ -78,4 +109,16 @@ export declare function billingResource(request: RequestFn): {
78
109
  deleted: true;
79
110
  }>;
80
111
  listSubscriptions(params?: ListSubscriptionsParams): Promise<ListPage<BillingSubscription>>;
112
+ /**
113
+ * Adopt an EXISTING Stripe subscription onto a user/org + plan, for
114
+ * migrating billing into Atlas without re-charging. Read-only on Stripe.
115
+ */
116
+ importSubscription(body: ImportBillingSubscriptionBody, idempotencyKey?: string): Promise<BillingSubscription>;
117
+ /** Report metered usage (mirrored to a Stripe meter event when the plan is metered). */
118
+ reportUsage(body: ReportBillingUsageBody): Promise<BillingUsageReport>;
119
+ /**
120
+ * Sync a per-seat subscription's Stripe quantity to the org's current member
121
+ * count (prorated). Never changes the paid status.
122
+ */
123
+ syncSeats(subjectType: "user" | "org", subjectId: string): Promise<BillingSeatSync>;
81
124
  };
@@ -22,6 +22,32 @@ function billingResource(request) {
22
22
  listSubscriptions(params) {
23
23
  return request({ method: 'GET', path: '/v1/billing/subscriptions', query: { ...params } });
24
24
  },
25
+ /**
26
+ * Adopt an EXISTING Stripe subscription onto a user/org + plan, for
27
+ * migrating billing into Atlas without re-charging. Read-only on Stripe.
28
+ */
29
+ importSubscription(body, idempotencyKey) {
30
+ return request({
31
+ method: 'POST',
32
+ path: '/v1/billing/subscriptions/import',
33
+ body,
34
+ idempotencyKey,
35
+ });
36
+ },
37
+ /** Report metered usage (mirrored to a Stripe meter event when the plan is metered). */
38
+ reportUsage(body) {
39
+ return request({ method: 'POST', path: '/v1/billing/usage', body });
40
+ },
41
+ /**
42
+ * Sync a per-seat subscription's Stripe quantity to the org's current member
43
+ * count (prorated). Never changes the paid status.
44
+ */
45
+ syncSeats(subjectType, subjectId) {
46
+ return request({
47
+ method: 'POST',
48
+ path: `/v1/billing/subjects/${(0, request_1.enc)(subjectType)}/${(0, request_1.enc)(subjectId)}/sync_seats`,
49
+ });
50
+ },
25
51
  };
26
52
  }
27
53
  //# sourceMappingURL=billing-plans.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"billing-plans.js","sourceRoot":"","sources":["../../src/client/billing-plans.ts"],"names":[],"mappings":";;AA2EA,0CAqBC;AAhGD,uCAAgD;AA2EhD,SAAgB,eAAe,CAAC,OAAkB;IAChD,OAAO;QACL,SAAS;YACP,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,UAAU,CAAC,IAA2B,EAAE,cAAuB;YAC7D,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QACtF,CAAC;QACD,OAAO,CAAC,EAAU;YAChB,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,qBAAqB,IAAA,aAAG,EAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,UAAU,CAAC,EAAU,EAAE,IAA2B;YAChD,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,qBAAqB,IAAA,aAAG,EAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAClF,CAAC;QACD,UAAU,CAAC,EAAU;YACnB,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,qBAAqB,IAAA,aAAG,EAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,CAAC;QACD,iBAAiB,CAAC,MAAgC;YAChD,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,2BAA2B,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7F,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"billing-plans.js","sourceRoot":"","sources":["../../src/client/billing-plans.ts"],"names":[],"mappings":";;AA8GA,0CAkDC;AAhKD,uCAAgD;AA8GhD,SAAgB,eAAe,CAAC,OAAkB;IAChD,OAAO;QACL,SAAS;YACP,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,UAAU,CAAC,IAA2B,EAAE,cAAuB;YAC7D,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QACtF,CAAC;QACD,OAAO,CAAC,EAAU;YAChB,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,qBAAqB,IAAA,aAAG,EAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,UAAU,CAAC,EAAU,EAAE,IAA2B;YAChD,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,qBAAqB,IAAA,aAAG,EAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAClF,CAAC;QACD,UAAU,CAAC,EAAU;YACnB,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,qBAAqB,IAAA,aAAG,EAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,CAAC;QACD,iBAAiB,CAAC,MAAgC;YAChD,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,2BAA2B,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QAC7F,CAAC;QACD;;;WAGG;QACH,kBAAkB,CAChB,IAAmC,EACnC,cAAuB;YAEvB,OAAO,OAAO,CAAC;gBACb,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,kCAAkC;gBACxC,IAAI;gBACJ,cAAc;aACf,CAAC,CAAC;QACL,CAAC;QACD,wFAAwF;QACxF,WAAW,CAAC,IAA4B;YACtC,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAAC;QACtE,CAAC;QACD;;;WAGG;QACH,SAAS,CAAC,WAA2B,EAAE,SAAiB;YACtD,OAAO,OAAO,CAAC;gBACb,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,wBAAwB,IAAA,aAAG,EAAC,WAAW,CAAC,IAAI,IAAA,aAAG,EAAC,SAAS,CAAC,aAAa;aAC9E,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}