auth0-deploy-cli 8.38.0 → 8.40.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 (35) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/lib/context/defaults.d.ts +1 -0
  3. package/lib/context/defaults.js +47 -0
  4. package/lib/context/directory/handlers/clientAuthCredentials.d.ts +5 -0
  5. package/lib/context/directory/handlers/clientAuthCredentials.js +13 -0
  6. package/lib/context/directory/handlers/clients.js +15 -0
  7. package/lib/context/directory/handlers/eventStreams.d.ts +5 -0
  8. package/lib/context/directory/handlers/eventStreams.js +52 -0
  9. package/lib/context/directory/handlers/index.js +6 -0
  10. package/lib/context/directory/handlers/rateLimitPolicies.d.ts +6 -0
  11. package/lib/context/directory/handlers/rateLimitPolicies.js +53 -0
  12. package/lib/context/yaml/handlers/clientAuthCredentials.d.ts +5 -0
  13. package/lib/context/yaml/handlers/clientAuthCredentials.js +13 -0
  14. package/lib/context/yaml/handlers/clients.js +15 -0
  15. package/lib/context/yaml/handlers/eventStreams.d.ts +5 -0
  16. package/lib/context/yaml/handlers/eventStreams.js +24 -0
  17. package/lib/context/yaml/handlers/index.js +6 -0
  18. package/lib/context/yaml/handlers/rateLimitPolicies.d.ts +6 -0
  19. package/lib/context/yaml/handlers/rateLimitPolicies.js +27 -0
  20. package/lib/tools/auth0/handlers/clientAuthCredentials.d.ts +26 -0
  21. package/lib/tools/auth0/handlers/clientAuthCredentials.js +216 -0
  22. package/lib/tools/auth0/handlers/clientAuthCredentialsPre.d.ts +37 -0
  23. package/lib/tools/auth0/handlers/clientAuthCredentialsPre.js +118 -0
  24. package/lib/tools/auth0/handlers/clients.js +38 -1
  25. package/lib/tools/auth0/handlers/connections.js +1 -0
  26. package/lib/tools/auth0/handlers/eventStreams.d.ts +58 -0
  27. package/lib/tools/auth0/handlers/eventStreams.js +186 -0
  28. package/lib/tools/auth0/handlers/index.js +10 -0
  29. package/lib/tools/auth0/handlers/prompts.js +1 -1
  30. package/lib/tools/auth0/handlers/rateLimitPolicies.d.ts +81 -0
  31. package/lib/tools/auth0/handlers/rateLimitPolicies.js +203 -0
  32. package/lib/tools/constants.d.ts +2 -0
  33. package/lib/tools/constants.js +2 -0
  34. package/lib/types.d.ts +5 -1
  35. package/package.json +1 -1
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.schema = void 0;
13
+ const default_1 = require("./default");
14
+ const client_1 = require("../client");
15
+ const logger_1 = __importDefault(require("../../../logger"));
16
+ exports.schema = {
17
+ type: 'array',
18
+ items: { type: 'object' },
19
+ };
20
+ const CREDENTIAL_TYPE_TO_METHOD = {
21
+ public_key: 'private_key_jwt',
22
+ x509_cert: 'self_signed_tls_client_auth',
23
+ cert_subject_dn: 'tls_client_auth',
24
+ };
25
+ class ClientAuthCredentialsHandler {
26
+ constructor({ client, config }) {
27
+ this.type = 'clientAuthCredentials';
28
+ this.existing = null;
29
+ this.client = client;
30
+ this.config = config;
31
+ }
32
+ async getType() {
33
+ return null;
34
+ }
35
+ async load() {
36
+ logger_1.default.info(`Retrieving ${this.type} data from Auth0`);
37
+ return { [this.type]: null };
38
+ }
39
+ async validate() {
40
+ return null;
41
+ }
42
+ async processChanges(assets) {
43
+ const { clients } = assets;
44
+ if (!clients)
45
+ return;
46
+ const allowDelete = this.config('AUTH0_ALLOW_DELETE') === true || this.config('AUTH0_ALLOW_DELETE') === 'true';
47
+ // Only process clients that have client_authentication_methods in config.
48
+ // Full deletion (absent field) is handled by ClientAuthCredentialsPreHandler at order 40,
49
+ // before clients.ts runs. This handler only manages create and partial delete.
50
+ const clientsWithCam = clients.filter((c) => c.client_authentication_methods !== undefined);
51
+ if (clientsWithCam.length === 0)
52
+ return;
53
+ // In directory mode client_id is stripped. Resolve names for PKI clients only.
54
+ const needsNameResolution = clientsWithCam.some((c) => !c.client_id);
55
+ let clientIdByName = new Map();
56
+ if (needsNameResolution) {
57
+ const existingClients = await (0, client_1.paginate)(this.client.clients.list, {
58
+ paginate: true,
59
+ is_global: false,
60
+ });
61
+ clientIdByName = new Map(existingClients.map((c) => [c.name, c.client_id]));
62
+ }
63
+ for (const client of clientsWithCam) {
64
+ const clientId = client.client_id || (client.name && clientIdByName.get(client.name));
65
+ if (!clientId)
66
+ continue;
67
+ client.client_id = clientId;
68
+ const clientName = client.name || clientId;
69
+ // Collect all desired credentials across all auth methods (only pem-bearing entries)
70
+ const desired = [];
71
+ if (client.client_authentication_methods) {
72
+ for (const [methodKey, methodVal] of Object.entries(client.client_authentication_methods)) {
73
+ const credentials = methodVal?.credentials || [];
74
+ for (const cred of credentials) {
75
+ if (!cred.pem)
76
+ continue;
77
+ desired.push({
78
+ name: cred.name,
79
+ pem: cred.pem,
80
+ credential_type: cred.credential_type || this.inferCredentialType(methodKey),
81
+ method: methodKey,
82
+ });
83
+ }
84
+ }
85
+ }
86
+ // pem is the opt-in signal: present field with no pem = skip (safe export→deploy);
87
+ // absent field = fall through to delete path (intentional removal).
88
+ if (desired.length === 0 && client.client_authentication_methods)
89
+ continue;
90
+ let existing = [];
91
+ try {
92
+ existing = (await this.client.clients.credentials.list(clientId));
93
+ }
94
+ catch (err) {
95
+ logger_1.default.warn(`clientAuthCredentials: failed to list credentials for client "${clientName}": ${err}`);
96
+ continue;
97
+ }
98
+ // No credentials in Auth0 and none desired — nothing to do.
99
+ if (existing.length === 0 && desired.length === 0)
100
+ continue;
101
+ // Warn if duplicate names exist in Auth0 — we can't match safely
102
+ const existingNames = existing.map((c) => c.name);
103
+ const duplicateNames = existingNames.filter((n, i) => existingNames.indexOf(n) !== i);
104
+ if (duplicateNames.length > 0) {
105
+ logger_1.default.warn(`clientAuthCredentials: client "${clientName}" has duplicate credential names in Auth0 [${duplicateNames.join(', ')}] — skipping credential reconciliation for this client`);
106
+ continue;
107
+ }
108
+ const existingByName = new Map(existing.map((c) => [c.name, c]));
109
+ const desiredNames = new Set(desired.map((d) => d.name));
110
+ const toCreate = desired.filter((d) => !existingByName.has(d.name));
111
+ const toDelete = existing.filter((e) => !desiredNames.has(e.name));
112
+ // Creates first — Auth0 allows max 2 credentials; both must exist simultaneously during rotation
113
+ // Track name→id so we can correctly attribute each created credential to its method later.
114
+ const createdIdByName = new Map();
115
+ for (const cred of toCreate) {
116
+ try {
117
+ const created = await this.client.clients.credentials.create(clientId, {
118
+ name: cred.name,
119
+ pem: cred.pem,
120
+ credential_type: cred.credential_type,
121
+ });
122
+ logger_1.default.info(`clientAuthCredentials: created credential "${cred.name}" on client "${clientName}"`);
123
+ createdIdByName.set(cred.name, created.id);
124
+ }
125
+ catch (err) {
126
+ logger_1.default.warn(`clientAuthCredentials: failed to create credential "${cred.name}" on client "${clientName}": ${err}`);
127
+ }
128
+ }
129
+ // Re-wire client_authentication_methods with final IDs (kept + newly created).
130
+ // This must happen BEFORE deletes — Auth0 rejects deleting a credential that
131
+ // is still referenced in client_authentication_methods.
132
+ const keptIds = existing.filter((e) => desiredNames.has(e.name)).map((e) => e.id);
133
+ const createdIds = [...createdIdByName.values()];
134
+ const finalIds = [...keptIds, ...createdIds];
135
+ let updatedAuthMethods = null;
136
+ if (finalIds.length > 0) {
137
+ // Build method→ids map. For kept credentials use Auth0's stored type to infer method;
138
+ // for created credentials use the method from the user's config entry (by name).
139
+ const methodToIds = {};
140
+ for (const id of finalIds) {
141
+ const fromExisting = existing.find((e) => e.id === id);
142
+ const createdName = [...createdIdByName.entries()].find(([, cid]) => cid === id)?.[0];
143
+ const fromDesired = createdName ? desired.find((d) => d.name === createdName) : undefined;
144
+ const methodKey = (fromExisting && this.inferMethodFromType(fromExisting.credential_type)) ||
145
+ (fromDesired && fromDesired.method) ||
146
+ Object.keys(client.client_authentication_methods)[0];
147
+ if (!methodToIds[methodKey])
148
+ methodToIds[methodKey] = [];
149
+ methodToIds[methodKey].push(id);
150
+ }
151
+ updatedAuthMethods = {};
152
+ for (const [methodKey, ids] of Object.entries(methodToIds)) {
153
+ updatedAuthMethods[methodKey] = { credentials: ids.map((id) => ({ id })) };
154
+ }
155
+ }
156
+ // Always update client_authentication_methods before deletes:
157
+ // - When finalIds > 0: re-wire to the remaining credentials
158
+ // - When finalIds === 0 but toDelete > 0: set to null so Auth0 de-references them first
159
+ if (finalIds.length > 0 || toDelete.length > 0) {
160
+ try {
161
+ const payload = {
162
+ client_authentication_methods: updatedAuthMethods ?? null,
163
+ };
164
+ // Auth0 requires token_endpoint_auth_method: null when setting client_authentication_methods,
165
+ // and a non-null value when clearing it.
166
+ if (updatedAuthMethods) {
167
+ payload.token_endpoint_auth_method = null;
168
+ }
169
+ else {
170
+ payload.token_endpoint_auth_method =
171
+ client.token_endpoint_auth_method || 'client_secret_post';
172
+ }
173
+ await this.client.clients.update(clientId, payload);
174
+ logger_1.default.info(`clientAuthCredentials: updated client_authentication_methods on client "${clientName}"`);
175
+ }
176
+ catch (err) {
177
+ logger_1.default.warn(`clientAuthCredentials: failed to update client_authentication_methods on client "${clientName}": ${err}`);
178
+ }
179
+ }
180
+ // Deletes last — after client_authentication_methods no longer references them
181
+ if (toDelete.length > 0) {
182
+ if (!allowDelete) {
183
+ logger_1.default.warn(`clientAuthCredentials: the following credentials on client "${clientName}" would be deleted but AUTH0_ALLOW_DELETE is not set:\n${toDelete
184
+ .map((c) => ` ${c.name} (${c.id})`)
185
+ .join('\n')}`);
186
+ }
187
+ else {
188
+ for (const cred of toDelete) {
189
+ try {
190
+ await this.client.clients.credentials.delete(clientId, cred.id);
191
+ logger_1.default.info(`clientAuthCredentials: deleted credential "${cred.name}" on client "${clientName}"`);
192
+ }
193
+ catch (err) {
194
+ logger_1.default.warn(`clientAuthCredentials: failed to delete credential "${cred.name}" on client "${clientName}": ${err}`);
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ inferCredentialType(methodKey) {
202
+ const map = {
203
+ private_key_jwt: 'public_key',
204
+ self_signed_tls_client_auth: 'x509_cert',
205
+ tls_client_auth: 'cert_subject_dn',
206
+ };
207
+ return map[methodKey] || 'public_key';
208
+ }
209
+ inferMethodFromType(credentialType) {
210
+ return CREDENTIAL_TYPE_TO_METHOD[credentialType] || 'private_key_jwt';
211
+ }
212
+ }
213
+ exports.default = ClientAuthCredentialsHandler;
214
+ __decorate([
215
+ (0, default_1.order)('70')
216
+ ], ClientAuthCredentialsHandler.prototype, "processChanges", null);
@@ -0,0 +1,37 @@
1
+ import { Assets, Auth0APIClient } from '../../../types';
2
+ import { ConfigFunction } from '../../../configFactory';
3
+ export declare const schema: {
4
+ type: string;
5
+ items: {
6
+ type: string;
7
+ };
8
+ };
9
+ /**
10
+ * Handles full credential deletion BEFORE clients.ts (order 50) patches the client.
11
+ *
12
+ * Auth0 rejects a client PATCH containing token_endpoint_auth_method while that client still
13
+ * has active credentials. By running at order 40, this handler clears credentials (and
14
+ * client_authentication_methods) for any client where the field is absent from config, so
15
+ * that clients.ts can safely include token_endpoint_auth_method in its PATCH.
16
+ *
17
+ * Partial deletion (some credentials removed, others kept) is handled by
18
+ * ClientAuthCredentialsHandler at order 70, because those clients still have
19
+ * client_authentication_methods present in config and clients.ts strips token_endpoint_auth_method
20
+ * for them anyway.
21
+ */
22
+ export default class ClientAuthCredentialsPreHandler {
23
+ client: Auth0APIClient;
24
+ config: ConfigFunction;
25
+ type: string;
26
+ existing: null;
27
+ constructor({ client, config }: {
28
+ client: Auth0APIClient;
29
+ config: ConfigFunction;
30
+ });
31
+ getType(): Promise<null>;
32
+ load(): Promise<{
33
+ [x: string]: null;
34
+ }>;
35
+ validate(): Promise<null>;
36
+ processChanges(assets: Assets): Promise<void>;
37
+ }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.schema = void 0;
13
+ const default_1 = require("./default");
14
+ const client_1 = require("../client");
15
+ const logger_1 = __importDefault(require("../../../logger"));
16
+ exports.schema = {
17
+ type: 'array',
18
+ items: { type: 'object' },
19
+ };
20
+ /**
21
+ * Handles full credential deletion BEFORE clients.ts (order 50) patches the client.
22
+ *
23
+ * Auth0 rejects a client PATCH containing token_endpoint_auth_method while that client still
24
+ * has active credentials. By running at order 40, this handler clears credentials (and
25
+ * client_authentication_methods) for any client where the field is absent from config, so
26
+ * that clients.ts can safely include token_endpoint_auth_method in its PATCH.
27
+ *
28
+ * Partial deletion (some credentials removed, others kept) is handled by
29
+ * ClientAuthCredentialsHandler at order 70, because those clients still have
30
+ * client_authentication_methods present in config and clients.ts strips token_endpoint_auth_method
31
+ * for them anyway.
32
+ */
33
+ class ClientAuthCredentialsPreHandler {
34
+ constructor({ client, config }) {
35
+ // Same type as ClientAuthCredentialsHandler so AUTH0_EXCLUDED / AUTH0_INCLUDED_ONLY
36
+ // applies to both handlers together without needing a separate AssetTypes entry.
37
+ this.type = 'clientAuthCredentials';
38
+ this.existing = null;
39
+ this.client = client;
40
+ this.config = config;
41
+ }
42
+ async getType() {
43
+ return null;
44
+ }
45
+ async load() {
46
+ return { [this.type]: null };
47
+ }
48
+ async validate() {
49
+ return null;
50
+ }
51
+ async processChanges(assets) {
52
+ const { clients } = assets;
53
+ if (!clients)
54
+ return;
55
+ const allowDelete = this.config('AUTH0_ALLOW_DELETE') === true || this.config('AUTH0_ALLOW_DELETE') === 'true';
56
+ // When allowDelete is false no deletion will happen — skip entirely to avoid
57
+ // unnecessary GET /credentials calls for every client.
58
+ if (!allowDelete)
59
+ return;
60
+ // Only act on clients where client_authentication_methods is absent from config.
61
+ // Absent = intentional full deletion. Clients with the field present (including partial
62
+ // deletion) are fully handled by ClientAuthCredentialsHandler at order 70.
63
+ const deletionCandidates = clients.filter((c) => c.client_authentication_methods === undefined);
64
+ if (deletionCandidates.length === 0)
65
+ return;
66
+ // In directory mode client_id is stripped. Resolve names once for all candidates.
67
+ const needsNameResolution = deletionCandidates.some((c) => !c.client_id);
68
+ let clientIdByName = new Map();
69
+ if (needsNameResolution) {
70
+ const existingClients = await (0, client_1.paginate)(this.client.clients.list, {
71
+ paginate: true,
72
+ is_global: false,
73
+ });
74
+ clientIdByName = new Map(existingClients.map((c) => [c.name, c.client_id]));
75
+ }
76
+ for (const client of deletionCandidates) {
77
+ const clientId = client.client_id || (client.name && clientIdByName.get(client.name));
78
+ if (!clientId)
79
+ continue;
80
+ const clientName = client.name || clientId;
81
+ let existing = [];
82
+ try {
83
+ existing = (await this.client.clients.credentials.list(clientId));
84
+ }
85
+ catch (err) {
86
+ logger_1.default.warn(`clientAuthCredentials: failed to list credentials for client "${clientName}": ${err}`);
87
+ continue;
88
+ }
89
+ if (existing.length === 0)
90
+ continue;
91
+ // De-reference credentials from client_authentication_methods before deleting them —
92
+ // Auth0 rejects deleting a credential that is still referenced.
93
+ try {
94
+ await this.client.clients.update(clientId, {
95
+ client_authentication_methods: null,
96
+ token_endpoint_auth_method: client.token_endpoint_auth_method || 'client_secret_post',
97
+ });
98
+ }
99
+ catch (err) {
100
+ logger_1.default.warn(`clientAuthCredentials: failed to clear client_authentication_methods on client "${clientName}": ${err}`);
101
+ continue;
102
+ }
103
+ for (const cred of existing) {
104
+ try {
105
+ await this.client.clients.credentials.delete(clientId, cred.id);
106
+ logger_1.default.info(`clientAuthCredentials: deleted credential "${cred.name}" on client "${clientName}"`);
107
+ }
108
+ catch (err) {
109
+ logger_1.default.warn(`clientAuthCredentials: failed to delete credential "${cred.name}" on client "${clientName}": ${err}`);
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ exports.default = ClientAuthCredentialsPreHandler;
116
+ __decorate([
117
+ (0, default_1.order)('40')
118
+ ], ClientAuthCredentialsPreHandler.prototype, "processChanges", null);
@@ -566,6 +566,17 @@ class ClientHandler extends default_1.default {
566
566
  delete item.refresh_token;
567
567
  }
568
568
  }
569
+ // Strip client_authentication_methods — the clientAuthCredentials handler (order 70)
570
+ // owns this field entirely. Auth0 rejects credential objects with name/credential_type in PATCH.
571
+ // Strip token_endpoint_auth_method only when client_authentication_methods is present in config:
572
+ // Auth0 rejects it in PATCH while a client has active credentials. For these clients the
573
+ // clientAuthCredentials handler (order 70) owns token_endpoint_auth_method too.
574
+ // For clients without client_authentication_methods, credentials were already cleared by
575
+ // clientAuthCredentialsPre (order 40), so token_endpoint_auth_method passes through safely.
576
+ if (item.client_authentication_methods) {
577
+ delete item.token_endpoint_auth_method;
578
+ }
579
+ delete item.client_authentication_methods;
569
580
  return item;
570
581
  });
571
582
  };
@@ -587,7 +598,33 @@ class ClientHandler extends default_1.default {
587
598
  is_global: false,
588
599
  ...((0, utils_1.shouldExcludeThirdPartyClients)(this.config) && { is_first_party: true }),
589
600
  });
590
- this.existing = createClientSanitizer(clients).sanitizeCrossOriginAuth(false).get();
601
+ const sanitized = createClientSanitizer(clients).sanitizeCrossOriginAuth(false).get();
602
+ // Enrich credential stubs with name and credential_type for export.
603
+ // Auth0 does not return pem on read — it is never exported.
604
+ await Promise.all(sanitized.map(async (client) => {
605
+ if (!client.client_authentication_methods)
606
+ return;
607
+ try {
608
+ const creds = await this.client.clients.credentials.list(client.client_id);
609
+ const credMap = new Map(creds.map((c) => [c.id, c]));
610
+ Object.values(client.client_authentication_methods).forEach((method) => {
611
+ if (method?.credentials) {
612
+ method.credentials = method.credentials
613
+ .map((stub) => {
614
+ const full = credMap.get(stub.id);
615
+ if (!full?.name)
616
+ return null;
617
+ return { name: full.name, credential_type: full.credential_type };
618
+ })
619
+ .filter(Boolean);
620
+ }
621
+ });
622
+ }
623
+ catch (_) {
624
+ // leave stubs as-is if the credentials API call fails
625
+ }
626
+ }));
627
+ this.existing = sanitized;
591
628
  return this.existing;
592
629
  }
593
630
  isCimdClient(client) {
@@ -85,6 +85,7 @@ const oidcOktaOnlyConnectionOptionFields = [
85
85
  'token_endpoint_auth_signing_alg',
86
86
  'id_token_signed_response_algs',
87
87
  'token_endpoint_jwtca_aud_format',
88
+ 'id_token_session_expiry_supported',
88
89
  ];
89
90
  exports.schema = {
90
91
  type: 'array',
@@ -0,0 +1,58 @@
1
+ import { Management } from 'auth0';
2
+ import DefaultAPIHandler from './default';
3
+ import { Asset, Assets } from '../../../types';
4
+ import { Action } from './actions';
5
+ export declare const schema: {
6
+ type: string;
7
+ items: {
8
+ type: string;
9
+ properties: {
10
+ id: {
11
+ type: string;
12
+ };
13
+ name: {
14
+ type: string;
15
+ };
16
+ status: {
17
+ type: string;
18
+ enum: string[];
19
+ };
20
+ subscriptions: {
21
+ type: string;
22
+ items: {
23
+ type: string;
24
+ properties: {
25
+ event_type: {
26
+ type: string;
27
+ };
28
+ };
29
+ };
30
+ };
31
+ destination: {
32
+ type: string;
33
+ properties: {
34
+ type: {
35
+ type: string;
36
+ enum: string[];
37
+ };
38
+ configuration: {
39
+ type: string;
40
+ };
41
+ };
42
+ required: string[];
43
+ };
44
+ };
45
+ required: string[];
46
+ };
47
+ };
48
+ export type EventStream = Management.EventStreamResponseContent;
49
+ export default class EventStreamsHandler extends DefaultAPIHandler {
50
+ existing: Asset[] | null;
51
+ private actions;
52
+ constructor(config: DefaultAPIHandler);
53
+ objString(item: Asset): string;
54
+ getActions(): Promise<Action[]>;
55
+ getType(): Promise<Asset[]>;
56
+ private resolveActionId;
57
+ processChanges(assets: Assets): Promise<void>;
58
+ }
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.schema = void 0;
46
+ const default_1 = __importStar(require("./default"));
47
+ const client_1 = require("../client");
48
+ const logger_1 = __importDefault(require("../../../logger"));
49
+ exports.schema = {
50
+ type: 'array',
51
+ items: {
52
+ type: 'object',
53
+ properties: {
54
+ id: { type: 'string' },
55
+ name: { type: 'string' },
56
+ status: { type: 'string', enum: ['enabled', 'disabled'] },
57
+ subscriptions: {
58
+ type: 'array',
59
+ items: {
60
+ type: 'object',
61
+ properties: {
62
+ event_type: { type: 'string' },
63
+ },
64
+ },
65
+ },
66
+ destination: {
67
+ type: 'object',
68
+ properties: {
69
+ type: { type: 'string', enum: ['webhook', 'eventbridge', 'action'] },
70
+ configuration: { type: 'object' },
71
+ },
72
+ required: ['type', 'configuration'],
73
+ },
74
+ },
75
+ required: ['name', 'destination'],
76
+ },
77
+ };
78
+ class EventStreamsHandler extends default_1.default {
79
+ constructor(config) {
80
+ super({
81
+ ...config,
82
+ type: 'eventStreams',
83
+ identifiers: ['id', 'name'],
84
+ // aws_partner_event_source is auto-populated by AWS after creation; sending it on create fails
85
+ stripCreateFields: [
86
+ 'destination.configuration.aws_partner_event_source',
87
+ 'created_at',
88
+ 'updated_at',
89
+ ],
90
+ stripUpdateFields: ['created_at', 'updated_at'],
91
+ });
92
+ this.actions = null;
93
+ }
94
+ objString(item) {
95
+ return super.objString(item.name);
96
+ }
97
+ async getActions() {
98
+ if (this.actions)
99
+ return this.actions;
100
+ this.actions = await (0, client_1.paginate)(this.client.actions.list, { paginate: true });
101
+ return this.actions;
102
+ }
103
+ async getType() {
104
+ if (this.existing) {
105
+ return this.existing;
106
+ }
107
+ const eventStreams = [];
108
+ let page = await this.client.eventStreams.list();
109
+ eventStreams.push(...page.data);
110
+ while (page.hasNextPage()) {
111
+ page = await page.getNextPage();
112
+ eventStreams.push(...page.data);
113
+ }
114
+ // For action-destination streams, replace action_id with the action name for export
115
+ const actions = await this.getActions();
116
+ this.existing = eventStreams.map((stream) => {
117
+ if (stream.destination?.type === 'action' && stream.destination.configuration?.action_id) {
118
+ const action = actions.find((a) => a.id === stream.destination.configuration.action_id);
119
+ if (action) {
120
+ return {
121
+ ...stream,
122
+ destination: {
123
+ ...stream.destination,
124
+ configuration: {
125
+ ...stream.destination.configuration,
126
+ action_id: action.name,
127
+ },
128
+ },
129
+ };
130
+ }
131
+ }
132
+ return stream;
133
+ });
134
+ return this.existing;
135
+ }
136
+ resolveActionId(stream) {
137
+ if (stream.destination?.type !== 'action' || !stream.destination.configuration?.action_id) {
138
+ return stream;
139
+ }
140
+ const name = stream.destination.configuration.action_id;
141
+ const action = (this.actions ?? []).find((a) => a.name === name);
142
+ if (!action) {
143
+ throw new Error(`Event stream "${stream.name}" references action "${name}" which was not found`);
144
+ }
145
+ return {
146
+ ...stream,
147
+ destination: {
148
+ ...stream.destination,
149
+ configuration: {
150
+ ...stream.destination.configuration,
151
+ action_id: action.id,
152
+ },
153
+ },
154
+ };
155
+ }
156
+ async processChanges(assets) {
157
+ const { eventStreams } = assets;
158
+ if (!eventStreams)
159
+ return;
160
+ if (!this.actions) {
161
+ this.actions = await this.getActions();
162
+ }
163
+ const changes = await this.calcChanges(assets).then((changesResponse) => ({
164
+ ...changesResponse,
165
+ create: changesResponse.create.map((stream) => this.resolveActionId(stream)),
166
+ update: changesResponse.update.map((stream) => {
167
+ const resolved = this.resolveActionId(stream);
168
+ // A destination's type cannot be changed once an event stream is created. The API
169
+ // rejects the destination on PATCH for eventbridge and action streams, so strip it
170
+ // from the update payload and only apply the other mutable fields.
171
+ if (resolved.destination?.type === 'eventbridge' ||
172
+ resolved.destination?.type === 'action') {
173
+ logger_1.default.info(`Skipping destination update for event stream "${resolved.name}": ${resolved.destination.type} destinations cannot be changed after creation.`);
174
+ const { destination: _dest, ...rest } = resolved;
175
+ return rest;
176
+ }
177
+ return resolved;
178
+ }),
179
+ }));
180
+ await super.processChanges(assets, changes);
181
+ }
182
+ }
183
+ exports.default = EventStreamsHandler;
184
+ __decorate([
185
+ (0, default_1.order)('75')
186
+ ], EventStreamsHandler.prototype, "processChanges", null);