@haakco/custd-sdk 0.0.0-stage → 3.71.1

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 (196) hide show
  1. package/README.md +958 -2
  2. package/dist/admin-accounting-evidence.d.ts +48 -0
  3. package/dist/admin-accounting-evidence.js +24 -0
  4. package/dist/admin-app-releases.d.ts +116 -0
  5. package/dist/admin-app-releases.js +8 -0
  6. package/dist/admin-apps.d.ts +120 -0
  7. package/dist/admin-apps.js +47 -0
  8. package/dist/admin-auth-project-domain.d.ts +125 -0
  9. package/dist/admin-auth-project-domain.js +37 -0
  10. package/dist/admin-auth-projects.d.ts +989 -0
  11. package/dist/admin-auth-projects.js +527 -0
  12. package/dist/admin-campaign-email.d.ts +120 -0
  13. package/dist/admin-campaign-email.js +64 -0
  14. package/dist/admin-client-setup.d.ts +122 -0
  15. package/dist/admin-client-setup.js +408 -0
  16. package/dist/admin-data-labels.d.ts +124 -0
  17. package/dist/admin-data-labels.js +51 -0
  18. package/dist/admin-data-scopes.d.ts +93 -0
  19. package/dist/admin-data-scopes.js +154 -0
  20. package/dist/admin-email-relay.d.ts +66 -0
  21. package/dist/admin-email-relay.js +25 -0
  22. package/dist/admin-environment-policy.d.ts +32 -0
  23. package/dist/admin-environment-policy.js +26 -0
  24. package/dist/admin-error-issues.d.ts +91 -0
  25. package/dist/admin-error-issues.js +52 -0
  26. package/dist/admin-event-types.d.ts +57 -0
  27. package/dist/admin-event-types.js +28 -0
  28. package/dist/admin-impersonation.d.ts +48 -0
  29. package/dist/admin-impersonation.js +27 -0
  30. package/dist/admin-ingest-claims.d.ts +35 -0
  31. package/dist/admin-ingest-claims.js +26 -0
  32. package/dist/admin-managed-audit.d.ts +13 -0
  33. package/dist/admin-managed-audit.js +13 -0
  34. package/dist/admin-measurement-projects.d.ts +166 -0
  35. package/dist/admin-measurement-projects.js +120 -0
  36. package/dist/admin-notification-destinations.d.ts +31 -0
  37. package/dist/admin-notification-destinations.js +19 -0
  38. package/dist/admin-notification-webhooks.d.ts +64 -0
  39. package/dist/admin-notification-webhooks.js +42 -0
  40. package/dist/admin-oauth-client-admissions.d.ts +65 -0
  41. package/dist/admin-oauth-client-admissions.js +46 -0
  42. package/dist/admin-offboarding.d.ts +123 -0
  43. package/dist/admin-offboarding.js +129 -0
  44. package/dist/admin-predictions.d.ts +266 -0
  45. package/dist/admin-predictions.js +93 -0
  46. package/dist/admin-privacy-erasures.d.ts +74 -0
  47. package/dist/admin-privacy-erasures.js +73 -0
  48. package/dist/admin-retention.d.ts +99 -0
  49. package/dist/admin-retention.js +60 -0
  50. package/dist/admin-rls.d.ts +94 -0
  51. package/dist/admin-rls.js +33 -0
  52. package/dist/admin-sdk-usage.d.ts +41 -0
  53. package/dist/admin-sdk-usage.js +23 -0
  54. package/dist/admin-site-ai.d.ts +72 -0
  55. package/dist/admin-site-ai.js +1 -0
  56. package/dist/admin-site-analytics.d.ts +52 -0
  57. package/dist/admin-site-analytics.js +14 -0
  58. package/dist/admin-site-audit-pages.d.ts +76 -0
  59. package/dist/admin-site-audit-pages.js +27 -0
  60. package/dist/admin-site-campaign-links.d.ts +40 -0
  61. package/dist/admin-site-campaign-links.js +9 -0
  62. package/dist/admin-site-domains.d.ts +733 -0
  63. package/dist/admin-site-domains.js +768 -0
  64. package/dist/admin-site-export.d.ts +76 -0
  65. package/dist/admin-site-export.js +15 -0
  66. package/dist/admin-site-insights-tasks.d.ts +44 -0
  67. package/dist/admin-site-insights-tasks.js +28 -0
  68. package/dist/admin-site-insights.d.ts +527 -0
  69. package/dist/admin-site-insights.js +61 -0
  70. package/dist/admin-site-links.d.ts +87 -0
  71. package/dist/admin-site-links.js +16 -0
  72. package/dist/admin-site-monitors.d.ts +110 -0
  73. package/dist/admin-site-monitors.js +25 -0
  74. package/dist/admin-site-next-actions.d.ts +93 -0
  75. package/dist/admin-site-next-actions.js +36 -0
  76. package/dist/admin-site-page-queries.d.ts +63 -0
  77. package/dist/admin-site-page-queries.js +20 -0
  78. package/dist/admin-site-rankings.d.ts +98 -0
  79. package/dist/admin-site-rankings.js +46 -0
  80. package/dist/admin-site-regional-trends.d.ts +30 -0
  81. package/dist/admin-site-regional-trends.js +1 -0
  82. package/dist/admin-site-saved-reports.d.ts +45 -0
  83. package/dist/admin-site-saved-reports.js +13 -0
  84. package/dist/admin-site-search-pool.d.ts +77 -0
  85. package/dist/admin-site-search-pool.js +41 -0
  86. package/dist/admin-site-search-value.d.ts +97 -0
  87. package/dist/admin-site-search-value.js +29 -0
  88. package/dist/admin-site-status-page.d.ts +57 -0
  89. package/dist/admin-site-status-page.js +10 -0
  90. package/dist/admin-site-traffic.d.ts +145 -0
  91. package/dist/admin-site-traffic.js +32 -0
  92. package/dist/admin-site-web-data.d.ts +258 -0
  93. package/dist/admin-site-web-data.js +60 -0
  94. package/dist/admin-subject-exports.d.ts +79 -0
  95. package/dist/admin-subject-exports.js +44 -0
  96. package/dist/admin-support-access.d.ts +32 -0
  97. package/dist/admin-support-access.js +21 -0
  98. package/dist/admin-system.d.ts +283 -0
  99. package/dist/admin-system.js +65 -0
  100. package/dist/admin-tenant-storage.d.ts +35 -0
  101. package/dist/admin-tenant-storage.js +24 -0
  102. package/dist/admin-timeplans.d.ts +512 -0
  103. package/dist/admin-timeplans.js +200 -0
  104. package/dist/admin-uncertainty-models.d.ts +42 -0
  105. package/dist/admin-uncertainty-models.js +53 -0
  106. package/dist/admin-usage.d.ts +124 -0
  107. package/dist/admin-usage.js +169 -0
  108. package/dist/admin-users.d.ts +124 -0
  109. package/dist/admin-users.js +82 -0
  110. package/dist/admin-workflow-timings.d.ts +367 -0
  111. package/dist/admin-workflow-timings.js +117 -0
  112. package/dist/analytics-events.d.ts +167 -0
  113. package/dist/analytics-events.js +197 -0
  114. package/dist/analytics-reads.d.ts +81 -0
  115. package/dist/analytics-reads.js +5 -0
  116. package/dist/app-account.d.ts +84 -0
  117. package/dist/app-account.js +177 -0
  118. package/dist/app-alerts.d.ts +120 -0
  119. package/dist/app-alerts.js +44 -0
  120. package/dist/app-items.d.ts +786 -0
  121. package/dist/app-items.js +524 -0
  122. package/dist/app-live.d.ts +84 -0
  123. package/dist/app-live.js +228 -0
  124. package/dist/app-meetings.d.ts +95 -0
  125. package/dist/app-meetings.js +26 -0
  126. package/dist/app-models.d.ts +271 -0
  127. package/dist/app-models.js +83 -0
  128. package/dist/app-push.d.ts +64 -0
  129. package/dist/app-push.js +178 -0
  130. package/dist/backend-lifecycle.d.ts +85 -0
  131. package/dist/backend-lifecycle.js +212 -0
  132. package/dist/browser-manifest.json +7 -0
  133. package/dist/browser-script-BWnwDjAC.js +711 -0
  134. package/dist/browser-script.d.ts +1 -0
  135. package/dist/browser-script.js +5 -0
  136. package/dist/browser-sign-in.d.ts +153 -0
  137. package/dist/browser-sign-in.js +410 -0
  138. package/dist/browser-tracker.d.ts +142 -0
  139. package/dist/browser-tracker.js +775 -0
  140. package/dist/browser-web-vitals.d.ts +22 -0
  141. package/dist/browser-web-vitals.js +116 -0
  142. package/dist/browser.d.ts +10 -0
  143. package/dist/browser.js +10 -0
  144. package/dist/download-stream.d.ts +16 -0
  145. package/dist/download-stream.js +55 -0
  146. package/dist/error-capture.d.ts +62 -0
  147. package/dist/error-capture.js +168 -0
  148. package/dist/hosted-app.d.ts +115 -0
  149. package/dist/hosted-app.js +275 -0
  150. package/dist/index.d.ts +2324 -0
  151. package/dist/index.js +2226 -0
  152. package/dist/ingest-operations.d.ts +483 -0
  153. package/dist/ingest-operations.js +154 -0
  154. package/dist/measurement.d.ts +164 -0
  155. package/dist/measurement.js +104 -0
  156. package/dist/mobile-adapter.d.ts +25 -0
  157. package/dist/mobile-adapter.js +57 -0
  158. package/dist/mobile-context.d.ts +32 -0
  159. package/dist/mobile-context.js +156 -0
  160. package/dist/mobile-queue.d.ts +22 -0
  161. package/dist/mobile-queue.js +73 -0
  162. package/dist/oauth.d.ts +1 -0
  163. package/dist/oauth.js +8 -0
  164. package/dist/parsers.d.ts +149 -0
  165. package/dist/parsers.js +115 -0
  166. package/dist/public-reads.d.ts +79 -0
  167. package/dist/public-reads.js +57 -0
  168. package/dist/reporting-catalogue.d.ts +264 -0
  169. package/dist/reporting-catalogue.js +5 -0
  170. package/dist/reporting-state.d.ts +46 -0
  171. package/dist/reporting-state.js +76 -0
  172. package/dist/response-lists.d.ts +16 -0
  173. package/dist/response-lists.generated.d.ts +7 -0
  174. package/dist/response-lists.generated.js +1927 -0
  175. package/dist/response-lists.js +70 -0
  176. package/dist/response-validation.d.ts +30 -0
  177. package/dist/response-validation.js +94 -0
  178. package/dist/runtime-readiness.d.ts +30 -0
  179. package/dist/runtime-readiness.js +150 -0
  180. package/dist/schema-registry.d.ts +45 -0
  181. package/dist/schema-registry.js +9 -0
  182. package/dist/secure-url.d.ts +4 -0
  183. package/dist/secure-url.js +23 -0
  184. package/dist/site-ai-owner.d.ts +34 -0
  185. package/dist/site-ai-owner.js +99 -0
  186. package/dist/site-monitor-reports.d.ts +15 -0
  187. package/dist/site-monitor-reports.js +87 -0
  188. package/dist/testing/fake-custd.d.ts +150 -0
  189. package/dist/testing/fake-custd.js +842 -0
  190. package/dist/testing/fake-results.d.ts +30 -0
  191. package/dist/testing/fake-results.js +293 -0
  192. package/dist/testing.d.ts +2 -0
  193. package/dist/testing.js +3 -0
  194. package/dist/version.d.ts +10 -0
  195. package/dist/version.js +10 -0
  196. package/package.json +57 -4
@@ -0,0 +1,527 @@
1
+ // AuthProjectAdminClient manages Custd projects, their environments, and the
2
+ // application principals a directory holds inside an environment through
3
+ // /api/v1/admin/auth-projects.
4
+ //
5
+ // Every call is a control-plane call that a machine credential may make only
6
+ // when it names the platform user it acts for. Set `owningUserUuid` on the
7
+ // call's RequestOptions and it is sent as X-Custd-Owning-User-UUID; Custd
8
+ // validates the named user as a live member of the machine caller's own
9
+ // company. A human administrator's own token subject is the actor and leaves
10
+ // the option unset.
11
+ import { appPath, } from "./admin-apps.js";
12
+ /**
13
+ * Raised when every step ran but the provider registrations are not known to
14
+ * describe the environment's current configuration: the honest answer for a
15
+ * provision that is not finished, rather than a success whose status is
16
+ * visibly unreconciled.
17
+ */
18
+ export class AuthProjectRealmNotConvergedError extends Error {
19
+ constructor(reconcileNote) {
20
+ super(`custd: auth-project realm did not converge${reconcileNote ? `: ${reconcileNote}` : ""}`);
21
+ this.reconcileNote = reconcileNote;
22
+ this.name = "AuthProjectRealmNotConvergedError";
23
+ }
24
+ }
25
+ /**
26
+ * Raised when a realm provision stops early. It carries the failed step and the
27
+ * receipt of every step that completed.
28
+ */
29
+ export class AuthProjectRealmProvisionError extends Error {
30
+ constructor(failedStep, receipt, cause) {
31
+ super(`custd: realm provision failed at step ${failedStep}`);
32
+ this.failedStep = failedStep;
33
+ this.receipt = receipt;
34
+ this.name = "AuthProjectRealmProvisionError";
35
+ this.cause = cause;
36
+ }
37
+ }
38
+ export class AuthProjectAdminClient {
39
+ constructor(request) {
40
+ this.request = request;
41
+ }
42
+ /**
43
+ * List up to 100 environments the named owning user owns or operates. Pass the
44
+ * previous page's `nextAfter` as `after` for the next page.
45
+ */
46
+ listProjects(after, options) {
47
+ const cursor = after === undefined ? "" : after.trim();
48
+ const path = cursor === "" ? "/auth-projects" : `/auth-projects?after=${encodeURIComponent(cursor)}`;
49
+ return this.request("GET", path, undefined, options);
50
+ }
51
+ /** Create the named owning user's project ownership, identity pool and first paused environment. */
52
+ async createProject(body, options) {
53
+ return this.request("POST", "/auth-projects", body, requireIdempotencyKey(options));
54
+ }
55
+ /**
56
+ * Record the authenticated human owner's company on an explicitly unbound historical project.
57
+ *
58
+ * It is the actionable step a `company_binding_required` refusal names: the body is empty, Custd
59
+ * refuses a machine credential and a foreign rebind, and repeating it for the same company is
60
+ * safe, so it carries no idempotency key.
61
+ */
62
+ bindProjectCompany(projectId, options) {
63
+ const path = `/auth-projects/${encodeURIComponent(projectId)}/company-binding`;
64
+ return this.request("POST", path, undefined, options);
65
+ }
66
+ /** Add a further environment to an existing project. The new environment starts paused. */
67
+ createEnvironment(projectId, body, options) {
68
+ const path = `/auth-projects/${encodeURIComponent(projectId)}/environments`;
69
+ return this.request("POST", path, body, options);
70
+ }
71
+ /** Report the sessions the directory currently holds for one application principal. */
72
+ listPrincipalSessions(projectId, environmentId, directoryId, providerSubject, options) {
73
+ const path = `${applicationPrincipalPath(projectId, environmentId, directoryId, providerSubject)}/sessions`;
74
+ return this.request("GET", path, undefined, options);
75
+ }
76
+ /** End exactly one of a principal's sessions, leaving its other sessions untouched. */
77
+ async revokePrincipalSession(projectId, environmentId, directoryId, providerSubject, body, options) {
78
+ const path = `${applicationPrincipalPath(projectId, environmentId, directoryId, providerSubject)}/sessions/revoke`;
79
+ return this.request("POST", path, body, requireIdempotencyKey(options));
80
+ }
81
+ /** End every session the directory holds for one application principal. */
82
+ async revokePrincipalSessions(projectId, environmentId, directoryId, providerSubject, body, options) {
83
+ const path = `${applicationPrincipalPath(projectId, environmentId, directoryId, providerSubject)}/sessions/revoke-all`;
84
+ return this.request("POST", path, body, requireIdempotencyKey(options));
85
+ }
86
+ /** Withdraw authority and revoke the sessions of every identity owned by this principal. */
87
+ async suspendPrincipal(target, options) {
88
+ const path = `${applicationPrincipalPath(target.projectId, target.environmentId, target.directoryId, target.providerSubject)}/suspend`;
89
+ return this.request("POST", path, undefined, requireIdempotencyKey(options));
90
+ }
91
+ /** Restore authority without changing factors; a pending erasure cannot be restored. */
92
+ async restorePrincipal(target, options) {
93
+ const path = `${applicationPrincipalPath(target.projectId, target.environmentId, target.directoryId, target.providerSubject)}/restore`;
94
+ return this.request("POST", path, undefined, requireIdempotencyKey(options));
95
+ }
96
+ /** Read the portable public record and its provider-trait completeness status. */
97
+ exportPrincipal(target, options) {
98
+ const path = `${applicationPrincipalPath(target.projectId, target.environmentId, target.directoryId, target.providerSubject)}/export`;
99
+ return this.request("GET", path, undefined, options);
100
+ }
101
+ /** Erase the complete principal-owned mapping set through the server's durable operation. */
102
+ async erasePrincipal(target, body, options) {
103
+ const path = `${applicationPrincipalPath(target.projectId, target.environmentId, target.directoryId, target.providerSubject)}/erase`;
104
+ return this.request("POST", path, body, requireIdempotencyKey(options));
105
+ }
106
+ /** End one application identity's membership of one organisation. */
107
+ revokePrincipalMembership(projectId, environmentId, directoryId, providerSubject, body, options) {
108
+ const path = `${applicationPrincipalPath(projectId, environmentId, directoryId, providerSubject)}/memberships/revoke`;
109
+ return this.request("POST", path, body, options);
110
+ }
111
+ /**
112
+ * Write the environment's desired state and return the operation receipt.
113
+ * Custd makes it retry-safe per Idempotency-Key, so the key is required. The
114
+ * audience binding the consumer's edge admits against is written here and read
115
+ * back through `getEnvironmentStatus`.
116
+ */
117
+ async applyEnvironmentDesiredState(projectId, environmentId, body, options) {
118
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/apply`;
119
+ return this.request("POST", path, body, requireIdempotencyKey(options));
120
+ }
121
+ /** Report the field-level changes an apply would make. A preview writes nothing. */
122
+ previewEnvironmentDesiredState(projectId, environmentId, body, options) {
123
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/preview`;
124
+ return this.request("POST", path, body, options);
125
+ }
126
+ /**
127
+ * Read the environment's configured state and applied revision. `status.desired.audiences`
128
+ * carries the applied audience binding and `status.environmentId` the
129
+ * environment binding, so a caller reads the mapping back here after an apply.
130
+ */
131
+ getEnvironmentStatus(projectId, environmentId, options) {
132
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/status`;
133
+ return this.request("GET", path, undefined, options);
134
+ }
135
+ /** Read the environment's most recent releases. Omit `limit` for the server default (20, capped at 100). */
136
+ listAppReleases(projectId, environmentId, limit, options) {
137
+ const path = appReleasesPath(projectId, environmentId);
138
+ return this.request("GET", limit ? `${path}?limit=${limit}` : path, undefined, options);
139
+ }
140
+ /** Record a new, pending release from its manifest. */
141
+ createAppRelease(projectId, environmentId, body, options) {
142
+ return this.request("POST", appReleasesPath(projectId, environmentId), body, options);
143
+ }
144
+ /**
145
+ * Store one manifest file of a pending release as its raw bytes. The server
146
+ * refuses bytes whose size or sha256 differ from the manifest.
147
+ */
148
+ uploadAppReleaseFile(projectId, environmentId, releaseId, filePath, bytes, options) {
149
+ const path = `${appReleasePath(projectId, environmentId, releaseId)}/files?path=${encodeURIComponent(filePath)}`;
150
+ return this.request("POST", path, bytes, options);
151
+ }
152
+ /** Read every file back and mark the release verified when all of them match the manifest. */
153
+ verifyAppRelease(projectId, environmentId, releaseId, options) {
154
+ const path = `${appReleasePath(projectId, environmentId, releaseId)}/verify`;
155
+ return this.request("POST", path, undefined, options);
156
+ }
157
+ /** Make a verified release the one the environment's host serves. */
158
+ promoteAppRelease(projectId, environmentId, releaseId, options) {
159
+ const path = `${appReleasePath(projectId, environmentId, releaseId)}/promote`;
160
+ return this.request("POST", path, undefined, options);
161
+ }
162
+ /**
163
+ * Create an app with hosting, traffic, error capture and app data on; `signIn` also turns on
164
+ * invite-only sign-in. Repeating the same body and Idempotency-Key finishes a create that did
165
+ * not complete (`app_setup_incomplete`) or reads the same app back, so the key is required.
166
+ */
167
+ async createApp(body, options) {
168
+ return this.request("POST", "/apps", body, requireIdempotencyKey(options));
169
+ }
170
+ /** List one page of the caller's apps, worst status first. Pass the previous `nextAfter` as `after`. */
171
+ listApps(after, options) {
172
+ const path = after ? `/apps?after=${encodeURIComponent(after)}` : "/apps";
173
+ return this.request("GET", path, undefined, options);
174
+ }
175
+ /** Read one app by its slug, with its latest release and link counts. */
176
+ getApp(slug, options) {
177
+ return this.request("GET", appPath(slug), undefined, options);
178
+ }
179
+ /** Create a CI credential that can deploy only this app, acting for the caller. Its secret is shown once. */
180
+ createAppDeployCredential(slug, options) {
181
+ return this.request("POST", `${appPath(slug)}/deploy-credentials`, undefined, options);
182
+ }
183
+ /** List the app's deploy credentials, newest first. */
184
+ async listAppDeployCredentials(slug, options) {
185
+ const path = `${appPath(slug)}/deploy-credentials`;
186
+ const list = await this.request("GET", path, undefined, options);
187
+ return { credentials: list.credentials ?? [] };
188
+ }
189
+ /** Take the app offline, keeping its releases and data. The Idempotency-Key finishes an incomplete pause. */
190
+ pauseApp(slug, options) {
191
+ return this.request("POST", `${appPath(slug)}/pause`, undefined, requireIdempotencyKey(options));
192
+ }
193
+ /** Serve the app again, with its newest verified release when none is active. */
194
+ resumeApp(slug, options) {
195
+ return this.request("POST", `${appPath(slug)}/resume`, undefined, requireIdempotencyKey(options));
196
+ }
197
+ /** Retry the app's Site registration and sign-in setup from its saved hosting configuration. */
198
+ repairApp(slug, options) {
199
+ return this.request("POST", `${appPath(slug)}/repair`, undefined, requireIdempotencyKey(options));
200
+ }
201
+ /** Change who may sign in to the app. Only the project owner may. */
202
+ setAppSignIn(slug, body, options) {
203
+ return this.request("POST", `${appPath(slug)}/sign-in`, body, requireIdempotencyKey(options));
204
+ }
205
+ /** Remove a deploy credential. Repeating a delete that failed part-way finishes it. */
206
+ async deleteAppDeployCredential(slug, clientId, options) {
207
+ const path = `${appPath(slug)}/deploy-credentials/${encodeURIComponent(clientId)}`;
208
+ await this.request("DELETE", path, undefined, options);
209
+ }
210
+ /** Read the environment's authentication hostname, its state and the DNS records it needs. */
211
+ getEnvironmentAuthDomain(projectId, environmentId, options) {
212
+ return this.authDomainRequest("GET", projectId, environmentId, "", undefined, options);
213
+ }
214
+ /** Reserve a verified hostname for the environment. */
215
+ bindEnvironmentAuthDomain(projectId, environmentId, body, options) {
216
+ return this.authDomainRequest("PUT", projectId, environmentId, "", body, options);
217
+ }
218
+ /** Reserve a platform-generated issuer hostname for an installed environment. Operators only. */
219
+ mintEnvironmentAuthDomain(projectId, environmentId, body, options) {
220
+ return this.authDomainRequest("POST", projectId, environmentId, "/mint", body, options);
221
+ }
222
+ /** Claim installed capacity for a reserved realm. A replay returns the same claim. */
223
+ admitEnvironmentAuthDomain(projectId, environmentId, options) {
224
+ return this.authDomainRequest("POST", projectId, environmentId, "/admit", undefined, options);
225
+ }
226
+ /** Ask for the hostname to be reconciled again. */
227
+ retryEnvironmentAuthDomain(projectId, environmentId, options) {
228
+ return this.authDomainRequest("POST", projectId, environmentId, "/retry", undefined, options);
229
+ }
230
+ /** Disable the issuer while keeping the hostname reserved. */
231
+ disableEnvironmentAuthDomain(projectId, environmentId, options) {
232
+ return this.authDomainRequest("POST", projectId, environmentId, "/disable", undefined, options);
233
+ }
234
+ /** Start the cleanup that frees the hostname for a new binding. */
235
+ releaseEnvironmentAuthDomain(projectId, environmentId, options) {
236
+ return this.authDomainRequest("POST", projectId, environmentId, "/release", undefined, options);
237
+ }
238
+ /** Pin one realm component to an exact incident image until it expires. System operators only. */
239
+ setEnvironmentAuthDomainImageOverride(projectId, environmentId, body, options) {
240
+ return this.authDomainRequest("PUT", projectId, environmentId, "/image-override", body, options);
241
+ }
242
+ /** End the realm's incident image override. */
243
+ clearEnvironmentAuthDomainImageOverride(projectId, environmentId, options) {
244
+ return this.authDomainRequest("DELETE", projectId, environmentId, "/image-override", undefined, options);
245
+ }
246
+ /** Upload or replace the realm's brand logo. The server checks the image format from its bytes. */
247
+ setAuthProjectBrandLogo(projectId, environmentId, logo, filename = "logo", options) {
248
+ const form = new FormData();
249
+ form.append("logo", logo, filename);
250
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/brand/logo`;
251
+ return this.request("POST", path, form, options);
252
+ }
253
+ /** Remove the realm's brand logo. */
254
+ async clearAuthProjectBrandLogo(projectId, environmentId, options) {
255
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/brand/logo`;
256
+ await this.request("DELETE", path, undefined, options);
257
+ }
258
+ /** List the owner and share links to app items in the environment. */
259
+ async listEnvironmentAppLinks(projectId, environmentId, options) {
260
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/app-links`;
261
+ const list = await this.request("GET", path, undefined, options);
262
+ return { links: list.links ?? [] };
263
+ }
264
+ authDomainRequest(method, projectId, environmentId, action, body, options) {
265
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/domain${action}`;
266
+ return this.request(method, path, body, options);
267
+ }
268
+ /** Read the environment's supported auth configuration. */
269
+ getEnvironmentCapability(projectId, environmentId, options) {
270
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/capability`;
271
+ return this.request("GET", path, undefined, options);
272
+ }
273
+ /** Report every directory in the environment and whether it is fully stored. */
274
+ listDirectories(projectId, environmentId, options) {
275
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/directories`;
276
+ return this.request("GET", path, undefined, options);
277
+ }
278
+ /** Enable, pause, resume or release one directory credential store. */
279
+ async actOnDirectory(projectId, environmentId, action, body, options) {
280
+ if (!directoryActions.includes(action)) {
281
+ throw new Error(`custd: auth-project directory action ${String(action)} is not one of enable, pause, resume or release`);
282
+ }
283
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/directories/${encodeURIComponent(action)}`;
284
+ return this.request("POST", path, body, requireIdempotencyKey(options));
285
+ }
286
+ /** Report the organisations one environment's directory holds. */
287
+ listEnvironmentOrganisations(projectId, environmentId, options) {
288
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/organisations`;
289
+ return this.request("GET", path, undefined, options);
290
+ }
291
+ /**
292
+ * List the application principals every directory in the environment holds. The
293
+ * owning-user header is taken from `options` like the other project-auth reads,
294
+ * and paging continues with the opaque `nextCursor` the previous page returned.
295
+ */
296
+ listPrincipals(projectId, environmentId, query = {}, options) {
297
+ const parts = [];
298
+ // The cursor is opaque: only an absent or genuinely empty value is dropped, and
299
+ // every other string is url-encoded byte-for-byte without normalization.
300
+ const cursor = query.cursor;
301
+ if (cursor !== undefined && cursor !== "") {
302
+ parts.push(`cursor=${encodeURIComponent(cursor)}`);
303
+ }
304
+ if (query.limit !== undefined && query.limit > 0) {
305
+ parts.push(`limit=${encodeURIComponent(String(query.limit))}`);
306
+ }
307
+ const suffix = parts.length === 0 ? "" : `?${parts.join("&")}`;
308
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/principals${suffix}`;
309
+ return this.request("GET", path, undefined, options);
310
+ }
311
+ /** Register the environment's application clients with the provider. */
312
+ async reconcileEnvironmentClients(projectId, environmentId, body, options) {
313
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/clients/reconcile`;
314
+ return this.request("POST", path, body, requireIdempotencyKey(options));
315
+ }
316
+ /** Report the environment's invitations, newest first. */
317
+ listInvitations(projectId, environmentId, options) {
318
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/invitations`;
319
+ return this.request("GET", path, undefined, options);
320
+ }
321
+ /** Invite one address into a directory and return the one-time link. */
322
+ async issueInvitation(projectId, environmentId, body, options) {
323
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/invitations`;
324
+ return this.request("POST", path, body, requireIdempotencyKey(options));
325
+ }
326
+ /** Withdraw a live invitation before it is used. */
327
+ async revokeInvitation(projectId, environmentId, body, options) {
328
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/invitations/revoke`;
329
+ return this.request("POST", path, body, requireIdempotencyKey(options));
330
+ }
331
+ /** Replace one live invitation's link and return the fresh one-time link. */
332
+ async redeliverInvitation(projectId, environmentId, body, options) {
333
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/invitations/redeliver`;
334
+ return this.request("POST", path, body, requireIdempotencyKey(options));
335
+ }
336
+ /** List admission state for the existing directory/provider-subject address. */
337
+ listPrincipalAudiences(target, options) {
338
+ const path = `${principalAudiencesPath(target)}?${new URLSearchParams({ directoryId: target.directoryId })}`;
339
+ return this.request("GET", path, undefined, options);
340
+ }
341
+ /** Grant exactly one audience; idempotent and audited server-side. */
342
+ async grantPrincipalAudience(target, body, options) {
343
+ return this.request("POST", `${principalAudiencesPath(target)}/grant`, body, requireIdempotencyKey(options));
344
+ }
345
+ /** Revoke only this audience, leaving sibling audiences and organisation membership untouched.
346
+ * Idempotent and audited server-side; no replacement audience is required.
347
+ */
348
+ async revokePrincipalAudience(target, body, options) {
349
+ return this.request("POST", `${principalAudiencesPath(target)}/revoke`, body, requireIdempotencyKey(options));
350
+ }
351
+ /** Read one application principal's profile values. */
352
+ getPrincipalProfile(target, options) {
353
+ const path = `${applicationPrincipalPath(target.projectId, target.environmentId, target.directoryId, target.providerSubject)}/profile`;
354
+ return this.request("GET", path, undefined, options);
355
+ }
356
+ /** Set one application principal's profile values as an upsert. */
357
+ async setPrincipalProfile(target, body, options) {
358
+ const path = `${applicationPrincipalPath(target.projectId, target.environmentId, target.directoryId, target.providerSubject)}/profile`;
359
+ return this.request("POST", path, body, requireIdempotencyKey(options));
360
+ }
361
+ /** List the organisations one application principal may act for. */
362
+ listPrincipalMemberships(target, options) {
363
+ const path = `${applicationPrincipalPath(target.projectId, target.environmentId, target.directoryId, target.providerSubject)}/memberships`;
364
+ return this.request("GET", path, undefined, options);
365
+ }
366
+ /** Delete a project and everything scoped to it. `confirmSlug` must name the stored project slug. */
367
+ deleteProject(projectId, body, options) {
368
+ const path = `/auth-projects/${encodeURIComponent(projectId)}/delete`;
369
+ return this.request("POST", path, body, options);
370
+ }
371
+ /** Delete one environment without touching its siblings. `confirmSlug` must name the stored environment slug. */
372
+ deleteEnvironment(projectId, environmentId, body, options) {
373
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/delete`;
374
+ return this.request("POST", path, body, options);
375
+ }
376
+ /**
377
+ * Withdraw one environment's authority and reconcile its owned provider clients
378
+ * away while retaining the environment and its identity data. It is the safe step
379
+ * for an environment whose directory still holds a credential store, which a
380
+ * physical delete refuses. `confirmSlug` must name the stored environment slug.
381
+ * The route has no idempotency key: a retry resumes the provider stage.
382
+ */
383
+ offboardEnvironment(projectId, environmentId, body, options) {
384
+ const path = `${environmentDesiredStatePath(projectId, environmentId)}/offboard`;
385
+ return this.request("POST", path, body, options);
386
+ }
387
+ /**
388
+ * Set one environment's identity realm up through the public control plane in
389
+ * the order the service requires, so a consumer does not have to sequence
390
+ * separate calls itself. Each write advances the environment's authority
391
+ * revision, so the order matters:
392
+ *
393
+ * 1. Apply the desired state (which also runs the client registration it implies).
394
+ * 2. Enable the directory credential store, naming the revision the apply produced.
395
+ * The service compares that revision against the environment's current revision,
396
+ * so a caller-supplied revision would conflict on every fresh setup.
397
+ * 3. Reconcile the environment's clients at the revision the directory enable
398
+ * produced, because the enable moved the revision past the observation the apply
399
+ * recorded and status reports a stale observation as unreconciled.
400
+ * 4. Read status and refuse to report success while the provider is not known to
401
+ * hold the configured registrations.
402
+ *
403
+ * Each mutating step derives a stable key from the base `idempotencyKey` in
404
+ * options, so retrying the whole call with the same base key resumes rather
405
+ * than duplicating. The base must be 8 to 111 characters, so every derived key
406
+ * stays within the service's 8 to 128 bound. On failure the thrown
407
+ * {@link AuthProjectRealmProvisionError} carries `failedStep` and the receipt
408
+ * of every step that completed, with the original error as its `cause`.
409
+ */
410
+ async provisionRealm(projectId, environmentId, request, options) {
411
+ const base = requireRealmBaseKey(options);
412
+ const receipt = { projectId, environmentId };
413
+ let apply;
414
+ try {
415
+ apply = await this.applyEnvironmentDesiredState(projectId, environmentId, request.desiredStateRequest, {
416
+ ...options,
417
+ idempotencyKey: `${base}:apply`,
418
+ });
419
+ }
420
+ catch (error) {
421
+ receipt.failedStep = "apply";
422
+ throw new AuthProjectRealmProvisionError("apply", receipt, error);
423
+ }
424
+ receipt.apply = apply;
425
+ // The enable names the revision the apply committed. The service compares the
426
+ // expected revision against the environment's current revision, which the apply
427
+ // just advanced, so the caller's read must not be reused here.
428
+ let directory;
429
+ try {
430
+ directory = await this.actOnDirectory(projectId, environmentId, "enable", { poolId: request.directoryPoolId, expectedRevision: apply.revision }, { ...options, idempotencyKey: `${base}:directory-enable` });
431
+ }
432
+ catch (error) {
433
+ receipt.failedStep = "directory_enable";
434
+ throw new AuthProjectRealmProvisionError("directory_enable", receipt, error);
435
+ }
436
+ receipt.directory = directory;
437
+ // Enabling advanced the revision again, so the observation the apply recorded is
438
+ // behind the environment. Reconcile at the directory's revision to record the
439
+ // provider state that describes the configuration as it is now.
440
+ let reconcile;
441
+ try {
442
+ reconcile = await this.reconcileEnvironmentClients(projectId, environmentId, { expectedRevision: directory.revision }, { ...options, idempotencyKey: `${base}:client-reconcile` });
443
+ }
444
+ catch (error) {
445
+ receipt.failedStep = "client_reconcile";
446
+ throw new AuthProjectRealmProvisionError("client_reconcile", receipt, error);
447
+ }
448
+ receipt.reconcile = reconcile;
449
+ // Status is a read, so it does not carry the workflow's write key.
450
+ let status;
451
+ try {
452
+ status = await this.getEnvironmentStatus(projectId, environmentId, {
453
+ ...options,
454
+ idempotencyKey: undefined,
455
+ });
456
+ }
457
+ catch (error) {
458
+ receipt.failedStep = "status";
459
+ throw new AuthProjectRealmProvisionError("status", receipt, error);
460
+ }
461
+ receipt.status = status;
462
+ if (!status.reconciled) {
463
+ receipt.failedStep = "status";
464
+ throw new AuthProjectRealmProvisionError("status", receipt, new AuthProjectRealmNotConvergedError(status.reconcileNote));
465
+ }
466
+ return receipt;
467
+ }
468
+ }
469
+ /** One directory credential-store action Custd defines. */
470
+ const directoryActions = ["enable", "pause", "resume", "release"];
471
+ // environmentDesiredStatePath addresses one environment under one project. Every
472
+ // segment is escaped so a caller-supplied identifier cannot reshape the path.
473
+ function environmentDesiredStatePath(projectId, environmentId) {
474
+ return `/auth-projects/${encodeURIComponent(projectId)}` + `/environments/${encodeURIComponent(environmentId)}`;
475
+ }
476
+ function appReleasesPath(projectId, environmentId) {
477
+ return `${environmentDesiredStatePath(projectId, environmentId)}/releases`;
478
+ }
479
+ function appReleasePath(projectId, environmentId, releaseId) {
480
+ return `${appReleasesPath(projectId, environmentId)}/${encodeURIComponent(releaseId)}`;
481
+ }
482
+ // applicationPrincipalPath addresses one application principal inside one
483
+ // directory. Every segment is escaped so a caller-supplied identifier cannot
484
+ // reshape the path.
485
+ function applicationPrincipalPath(projectId, environmentId, directoryId, providerSubject) {
486
+ return (`/auth-projects/${encodeURIComponent(projectId)}` +
487
+ `/environments/${encodeURIComponent(environmentId)}` +
488
+ `/directories/${encodeURIComponent(directoryId)}` +
489
+ `/principals/${encodeURIComponent(providerSubject)}`);
490
+ }
491
+ // requireIdempotencyKey rejects an empty key on the routes Custd makes
492
+ // retry-safe, so a caller gets one clear error instead of a service 400.
493
+ function requireIdempotencyKey(options) {
494
+ const key = options?.idempotencyKey;
495
+ if (typeof key !== "string" || key.trim() === "") {
496
+ throw new Error("custd: auth-project idempotency key is required");
497
+ }
498
+ return options ?? {};
499
+ }
500
+ // The service bounds an Idempotency-Key at 8 to 128 characters. A realm provision
501
+ // derives one key per mutating step by appending a suffix to the caller's base key,
502
+ // so the base itself is bounded here to keep every derived key legal. The longest
503
+ // suffix is ":directory-enable" (17 characters), matching the Go contract.
504
+ const realmMinKeyLength = 8;
505
+ const realmMaxKeyLength = 128;
506
+ const realmLongestSuffix = ":directory-enable";
507
+ // requireRealmBaseKey validates the workflow's base key before any request is sent,
508
+ // so a caller gets one clear error instead of a service rejection on a derived key
509
+ // whose suffix pushed it past the bound.
510
+ function requireRealmBaseKey(options) {
511
+ const base = options?.idempotencyKey?.trim() ?? "";
512
+ if (base === "") {
513
+ throw new Error("custd: auth-project realm provision requires a base idempotency key");
514
+ }
515
+ if (base.length < realmMinKeyLength) {
516
+ throw new Error(`custd: auth-project realm base idempotency key must be at least ${realmMinKeyLength} characters`);
517
+ }
518
+ const maxBase = realmMaxKeyLength - realmLongestSuffix.length;
519
+ if (base.length > maxBase) {
520
+ throw new Error(`custd: auth-project realm base idempotency key must be at most ${maxBase} characters so every per-step key stays within ${realmMaxKeyLength}`);
521
+ }
522
+ return base;
523
+ }
524
+ // Audience routes use the same provider-subject identity, with directoryId outside the path.
525
+ function principalAudiencesPath(target) {
526
+ return `${environmentDesiredStatePath(target.projectId, target.environmentId)}/principals/${encodeURIComponent(target.providerSubject)}/audiences`;
527
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Campaign email: published revisions and their rendering, scheduled runs, recipient permission, and
3
+ * the welcome journey (welcome then reminder) driven by confirmed signups and activations.
4
+ */
5
+ import type { CampaignEmailSelection } from "./admin-email-relay.js";
6
+ import type { RequestOptions } from "./index.js";
7
+ type AdminRequester = <T>(method: string, path: string, body?: unknown, options?: RequestOptions) => Promise<T>;
8
+ /** A published, immutable campaign revision. artifactJson is the campaign artifact as text. */
9
+ export type CampaignEmailRevision = {
10
+ revision: string;
11
+ artifactJson: string;
12
+ publishedAt: string;
13
+ };
14
+ export type CampaignEmailRevisionPublishRequest = {
15
+ revision: string;
16
+ artifactJson: string;
17
+ };
18
+ export type CampaignEmailRenderRequest = {
19
+ slots: Record<string, string>;
20
+ };
21
+ export type CampaignEmailRenderResult = {
22
+ companyUuid: string;
23
+ subject: string;
24
+ html: string;
25
+ text: string;
26
+ };
27
+ export type CampaignEmailRunScheduleRequest = {
28
+ /** The caller-chosen run UUID, so a retried schedule is the same run. */
29
+ id: string;
30
+ campaign: CampaignEmailSelection;
31
+ recipients: string[];
32
+ scheduledAt: string;
33
+ audienceDigest?: string;
34
+ };
35
+ export type CampaignEmailRunRecipientStatus = {
36
+ position: number;
37
+ state: string;
38
+ deliveryUuid?: string;
39
+ reason?: string;
40
+ };
41
+ export type CampaignEmailRunStatus = {
42
+ id: string;
43
+ revision: string;
44
+ scheduledAt: string;
45
+ cancelledAt?: string;
46
+ recipients: number;
47
+ pending: number;
48
+ processing: number;
49
+ sent: number;
50
+ failed: number;
51
+ excluded: number;
52
+ cancelled: number;
53
+ deliveries: CampaignEmailRunRecipientStatus[];
54
+ };
55
+ export type CampaignEmailRecipient = {
56
+ email: string;
57
+ };
58
+ export type CampaignEmailConfirmation = {
59
+ email: string;
60
+ confirmedAt: string;
61
+ source: string;
62
+ evidenceRef: string;
63
+ };
64
+ export type CampaignEmailPermission = {
65
+ eligible: boolean;
66
+ confirmedAt?: string;
67
+ withdrawnAt?: string;
68
+ };
69
+ export type CampaignWelcomeDefinition = {
70
+ version: string;
71
+ welcome: CampaignEmailSelection;
72
+ reminder: CampaignEmailSelection;
73
+ };
74
+ /** Pauses the welcome journey when true and resumes it when false. */
75
+ export type CampaignWelcomePause = {
76
+ paused: boolean;
77
+ };
78
+ export type CampaignWelcomeState = {
79
+ version: string;
80
+ paused: boolean;
81
+ };
82
+ export type CampaignWelcomeSignup = {
83
+ contactId: string;
84
+ email: string;
85
+ confirmedAt: string;
86
+ evidenceRef: string;
87
+ evidenceSource: string;
88
+ };
89
+ export type CampaignWelcomeActivation = {
90
+ contactId: string;
91
+ activatedAt: string;
92
+ };
93
+ export type CampaignWelcomeEnrollment = {
94
+ contactId: string;
95
+ version?: string;
96
+ welcomeRunId?: string;
97
+ reminderRunId?: string;
98
+ earliestReminderAt?: string;
99
+ activatedAt?: string;
100
+ };
101
+ export declare class CampaignEmailAdminClient {
102
+ private readonly request;
103
+ constructor(request: AdminRequester);
104
+ createRevision(body: CampaignEmailRevisionPublishRequest, companySlug?: string): Promise<CampaignEmailRevision>;
105
+ getRevision(revision: string, companySlug?: string): Promise<CampaignEmailRevision>;
106
+ renderRevision(revision: string, body: CampaignEmailRenderRequest): Promise<CampaignEmailRenderResult>;
107
+ startRun(body: CampaignEmailRunScheduleRequest, companySlug?: string): Promise<CampaignEmailRunStatus>;
108
+ getRun(runId: string, companySlug?: string): Promise<CampaignEmailRunStatus>;
109
+ cancelRun(runId: string, companySlug?: string): Promise<CampaignEmailRunStatus>;
110
+ checkPermission(body: CampaignEmailRecipient, companySlug?: string): Promise<CampaignEmailPermission>;
111
+ confirmPermission(body: CampaignEmailConfirmation, companySlug?: string): Promise<CampaignEmailPermission>;
112
+ withdrawPermission(body: CampaignEmailRecipient, companySlug?: string): Promise<CampaignEmailPermission>;
113
+ putWelcomeDefinition(body: CampaignWelcomeDefinition, companySlug?: string): Promise<CampaignWelcomeState>;
114
+ setWelcomePaused(body: CampaignWelcomePause, companySlug?: string): Promise<CampaignWelcomeState>;
115
+ recordWelcomeConfirmedSignup(body: CampaignWelcomeSignup, companySlug?: string): Promise<CampaignWelcomeEnrollment>;
116
+ recordWelcomeActivation(body: CampaignWelcomeActivation, companySlug?: string): Promise<CampaignWelcomeEnrollment>;
117
+ getWelcomeContact(contactId: string, companySlug?: string): Promise<CampaignWelcomeEnrollment>;
118
+ private run;
119
+ }
120
+ export {};