@transcend-io/cli 4.36.0 → 4.38.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.
- package/README.md +72 -7
- package/build/api-keys/generateCrossAccountApiKeys.d.ts +38 -0
- package/build/api-keys/generateCrossAccountApiKeys.d.ts.map +1 -0
- package/build/api-keys/generateCrossAccountApiKeys.js +90 -0
- package/build/api-keys/generateCrossAccountApiKeys.js.map +1 -0
- package/build/api-keys/index.d.ts +3 -0
- package/build/api-keys/index.d.ts.map +1 -0
- package/build/api-keys/index.js +15 -0
- package/build/api-keys/index.js.map +1 -0
- package/build/api-keys/validateTranscendAuth.d.ts +10 -0
- package/build/api-keys/validateTranscendAuth.d.ts.map +1 -0
- package/build/api-keys/validateTranscendAuth.js +54 -0
- package/build/api-keys/validateTranscendAuth.js.map +1 -0
- package/build/cli-generate-cross-account-api-keys.d.ts +3 -0
- package/build/cli-generate-cross-account-api-keys.d.ts.map +1 -0
- package/build/cli-generate-cross-account-api-keys.js +87 -0
- package/build/cli-generate-cross-account-api-keys.js.map +1 -0
- package/build/cli-push.js +61 -15
- package/build/cli-push.js.map +1 -1
- package/build/codecs.d.ts +13 -0
- package/build/codecs.d.ts.map +1 -1
- package/build/codecs.js +12 -1
- package/build/codecs.js.map +1 -1
- package/build/graphql/buildTranscendGraphQLClient.d.ts +8 -0
- package/build/graphql/buildTranscendGraphQLClient.d.ts.map +1 -1
- package/build/graphql/buildTranscendGraphQLClient.js +17 -4
- package/build/graphql/buildTranscendGraphQLClient.js.map +1 -1
- package/build/graphql/fetchAllAttributes.js +1 -1
- package/build/graphql/fetchAllAttributes.js.map +1 -1
- package/build/graphql/fetchApiKeys.d.ts +8 -0
- package/build/graphql/fetchApiKeys.d.ts.map +1 -1
- package/build/graphql/fetchApiKeys.js +23 -11
- package/build/graphql/fetchApiKeys.js.map +1 -1
- package/build/graphql/fetchConsentManagerId.d.ts +3 -2
- package/build/graphql/fetchConsentManagerId.d.ts.map +1 -1
- package/build/graphql/fetchConsentManagerId.js +4 -3
- package/build/graphql/fetchConsentManagerId.js.map +1 -1
- package/build/graphql/fetchDataSubjects.d.ts.map +1 -1
- package/build/graphql/fetchDataSubjects.js +1 -0
- package/build/graphql/fetchDataSubjects.js.map +1 -1
- package/build/graphql/fetchIdentifiers.d.ts +2 -1
- package/build/graphql/fetchIdentifiers.d.ts.map +1 -1
- package/build/graphql/fetchIdentifiers.js +9 -5
- package/build/graphql/fetchIdentifiers.js.map +1 -1
- package/build/graphql/fetchPrivacyCenterId.d.ts +9 -0
- package/build/graphql/fetchPrivacyCenterId.d.ts.map +1 -0
- package/build/graphql/fetchPrivacyCenterId.js +17 -0
- package/build/graphql/fetchPrivacyCenterId.js.map +1 -0
- package/build/graphql/gqls/apiKey.d.ts +2 -0
- package/build/graphql/gqls/apiKey.d.ts.map +1 -1
- package/build/graphql/gqls/apiKey.js +19 -1
- package/build/graphql/gqls/apiKey.js.map +1 -1
- package/build/graphql/gqls/auth.d.ts +4 -0
- package/build/graphql/gqls/auth.d.ts.map +1 -0
- package/build/graphql/gqls/auth.js +45 -0
- package/build/graphql/gqls/auth.js.map +1 -0
- package/build/graphql/gqls/consentManager.d.ts +1 -0
- package/build/graphql/gqls/consentManager.d.ts.map +1 -1
- package/build/graphql/gqls/consentManager.js +10 -1
- package/build/graphql/gqls/consentManager.js.map +1 -1
- package/build/graphql/gqls/identifier.d.ts.map +1 -1
- package/build/graphql/gqls/identifier.js +2 -5
- package/build/graphql/gqls/identifier.js.map +1 -1
- package/build/graphql/gqls/index.d.ts +2 -0
- package/build/graphql/gqls/index.d.ts.map +1 -1
- package/build/graphql/gqls/index.js +2 -0
- package/build/graphql/gqls/index.js.map +1 -1
- package/build/graphql/gqls/privacyCenter.d.ts +3 -0
- package/build/graphql/gqls/privacyCenter.d.ts.map +1 -0
- package/build/graphql/gqls/privacyCenter.js +19 -0
- package/build/graphql/gqls/privacyCenter.js.map +1 -0
- package/build/graphql/index.d.ts +3 -1
- package/build/graphql/index.d.ts.map +1 -1
- package/build/graphql/index.js +3 -1
- package/build/graphql/index.js.map +1 -1
- package/build/graphql/loginUser.d.ts +46 -0
- package/build/graphql/loginUser.d.ts.map +1 -0
- package/build/graphql/loginUser.js +51 -0
- package/build/graphql/loginUser.js.map +1 -0
- package/build/graphql/makeGraphQLRequest.d.ts +2 -1
- package/build/graphql/makeGraphQLRequest.d.ts.map +1 -1
- package/build/graphql/makeGraphQLRequest.js +5 -4
- package/build/graphql/makeGraphQLRequest.js.map +1 -1
- package/build/graphql/manageApiKeys.d.ts +31 -0
- package/build/graphql/manageApiKeys.d.ts.map +1 -0
- package/build/graphql/manageApiKeys.js +28 -0
- package/build/graphql/manageApiKeys.js.map +1 -0
- package/build/graphql/syncAction.d.ts +3 -1
- package/build/graphql/syncAction.d.ts.map +1 -1
- package/build/graphql/syncAction.js +2 -4
- package/build/graphql/syncAction.js.map +1 -1
- package/build/graphql/syncConfigurationToTranscend.d.ts +6 -1
- package/build/graphql/syncConfigurationToTranscend.d.ts.map +1 -1
- package/build/graphql/syncConfigurationToTranscend.js +29 -8
- package/build/graphql/syncConfigurationToTranscend.js.map +1 -1
- package/build/graphql/syncConsentManager.d.ts.map +1 -1
- package/build/graphql/syncConsentManager.js +21 -1
- package/build/graphql/syncConsentManager.js.map +1 -1
- package/build/graphql/syncDataFlows.js +2 -2
- package/build/graphql/syncDataFlows.js.map +1 -1
- package/build/graphql/syncDataSubject.d.ts +3 -1
- package/build/graphql/syncDataSubject.d.ts.map +1 -1
- package/build/graphql/syncDataSubject.js +3 -6
- package/build/graphql/syncDataSubject.js.map +1 -1
- package/build/graphql/syncIdentifier.d.ts +3 -1
- package/build/graphql/syncIdentifier.d.ts.map +1 -1
- package/build/graphql/syncIdentifier.js +2 -4
- package/build/graphql/syncIdentifier.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/tsbuildinfo +1 -1
- package/package.json +2 -1
- package/build/graphql/sleepPromise.d.ts +0 -8
- package/build/graphql/sleepPromise.d.ts.map +0 -1
- package/build/graphql/sleepPromise.js +0 -16
- package/build/graphql/sleepPromise.js.map +0 -1
package/README.md
CHANGED
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
- [Authentication](#authentication-10)
|
|
54
54
|
- [Arguments](#arguments-10)
|
|
55
55
|
- [Usage](#usage-11)
|
|
56
|
+
- [tr-generate-api-keys](#tr-generate-api-keys)
|
|
57
|
+
- [Authentication](#authentication-11)
|
|
58
|
+
- [Arguments](#arguments-11)
|
|
59
|
+
- [Usage](#usage-12)
|
|
56
60
|
|
|
57
61
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
58
62
|
|
|
@@ -382,13 +386,13 @@ The API key needs the following scopes when pushing the various resource types:
|
|
|
382
386
|
|
|
383
387
|
#### Arguments
|
|
384
388
|
|
|
385
|
-
| Argument | Description | Type
|
|
386
|
-
| ------------ | ----------------------------------------------------------------------------------------------------------- |
|
|
387
|
-
| auth | The Transcend API capable of pushing the configuration | string
|
|
388
|
-
| file | Path to the YAML file to push from | string - file-path
|
|
389
|
-
| transcendUrl | URL of the Transcend backend. Use https://api.us.transcend.io for US hosting. | string - URL
|
|
390
|
-
| pageSize | The page size to use when paginating over the API | number
|
|
391
|
-
| variables | The variables to template into the YAML file when pushing configuration. e.g. domain:acme.com,stage:staging | string
|
|
389
|
+
| Argument | Description | Type | Default | Required |
|
|
390
|
+
| ------------ | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------ | -------- |
|
|
391
|
+
| auth | The Transcend API capable of pushing the configuration | string (API key or path to tr-generate-api-keys JSON output) | N/A | true |
|
|
392
|
+
| file | Path to the YAML file to push from | string - file-path | ./transcend.yml | false |
|
|
393
|
+
| transcendUrl | URL of the Transcend backend. Use https://api.us.transcend.io for US hosting. | string - URL | https://api.transcend.io | false |
|
|
394
|
+
| pageSize | The page size to use when paginating over the API | number | 50 | false |
|
|
395
|
+
| variables | The variables to template into the YAML file when pushing configuration. e.g. domain:acme.com,stage:staging | string | N/A | false |
|
|
392
396
|
|
|
393
397
|
#### Usage
|
|
394
398
|
|
|
@@ -404,6 +408,15 @@ An alternative file destination can be specified:
|
|
|
404
408
|
tr-push --auth=$TRANSCEND_API_KEY --file=./custom/location.yml
|
|
405
409
|
```
|
|
406
410
|
|
|
411
|
+
Push changes to multiple Transcend instances using the output of [tr-generate-api-keys](#tr-generate-api-keys)
|
|
412
|
+
|
|
413
|
+
```sh
|
|
414
|
+
tr-generate-api-keys --email=test@transcend.io --password=$TRANSCEND_PASSWORD \
|
|
415
|
+
--scopes="View Email Templates,View Data Map" --apiKeyTitle="CLI Usage Cross Instance Sync" --file=./transcend-api-keys.json
|
|
416
|
+
tr-pull --auth=$TRANSCEND_API_KEY
|
|
417
|
+
tr-push --auth=./transcend-api-keys.json
|
|
418
|
+
```
|
|
419
|
+
|
|
407
420
|
Some things to note about this sync process:
|
|
408
421
|
|
|
409
422
|
1. Any field that is defined in your .yml file will be synced up to app.transcend.io. If any change was made on the admin dashboard, it will be overwritten.
|
|
@@ -1068,3 +1081,55 @@ Specifying the backend URL, needed for US hosted backend infrastructure.
|
|
|
1068
1081
|
yarn tr-retry-request-data-silos --auth=$TRANSCEND_API_KEY --dataSiloId=70810f2e-cf90-43f6-9776-901a5950599f --actions=ACCESS \
|
|
1069
1082
|
--transcendUrl=https://api.us.transcend.io
|
|
1070
1083
|
```
|
|
1084
|
+
|
|
1085
|
+
### tr-generate-api-keys
|
|
1086
|
+
|
|
1087
|
+
This command allows for creating API keys across multiple Transcend instances. This is useful for customers that are managing many Transcend instances and need to regularly create, cycle or delete API keys across all of their instances. Unlike the other commands that rely on API key authentication, this command relies upon username/password authentication. This command will spit out the API keys into a [JSON file](./examples/api-keys.json), and that JSON file can be used in subsequent cli commands.
|
|
1088
|
+
|
|
1089
|
+
#### Authentication
|
|
1090
|
+
|
|
1091
|
+
In order to use this command, you will need to provide your email and password for the Transcend account. This command will only generate API keys for Transcend instances where you have the permission to "Manage API Keys".
|
|
1092
|
+
|
|
1093
|
+
#### Arguments
|
|
1094
|
+
|
|
1095
|
+
| Argument | Description | Type | Default | Required |
|
|
1096
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------ | ------------------------ | -------- |
|
|
1097
|
+
| email | The email address that you use to [log into Transcend](https://app.transcend.io/login). | string | N/A | true |
|
|
1098
|
+
| password | The password for your account login. | string | N/A | true |
|
|
1099
|
+
| apiKeyTitle | The title of the API key being generated or destroyed. | string | N/A | true |
|
|
1100
|
+
| file | The file where API keys should be written to. | string - file-path | N/A | true |
|
|
1101
|
+
| scopes | The list of [scopes](https://docs.transcend.io/docs/security/access-control#scopes) that should be given to the API key. | string[] | N/A | true |
|
|
1102
|
+
| deleteExistingApiKey | When true, if an API key exists with the specified "apiKeyTitle", the existing API key is deleted. When false, an error is thrown if API key already exists. | boolean | true | false |
|
|
1103
|
+
| createNewApiKey | When true, new API keys will be created. Set to false if you simply want to delete all API keys with a title. | boolean | true | false |
|
|
1104
|
+
| transcendUrl | URL of the Transcend backend. Use https://api.us.transcend.io for US hosting. | string - URL | https://api.transcend.io | false |
|
|
1105
|
+
|
|
1106
|
+
#### Usage
|
|
1107
|
+
|
|
1108
|
+
```sh
|
|
1109
|
+
yarn tr-generate-api-keys --email=test@transcend.io --password=$TRANSCEND_PASSWORD \
|
|
1110
|
+
--scopes="View Email Templates,View Data Map" --apiKeyTitle="CLI Usage Cross Instance Sync" -file=./working/auth.json
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
Specifying the backend URL, needed for US hosted backend infrastructure.
|
|
1114
|
+
|
|
1115
|
+
```sh
|
|
1116
|
+
yarn tr-generate-api-keys --email=test@transcend.io --password=$TRANSCEND_PASSWORD \
|
|
1117
|
+
--scopes="View Email Templates,View Data Map" --apiKeyTitle="CLI Usage Cross Instance Sync" -file=./working/auth.json \
|
|
1118
|
+
--transcendUrl=https://api.us.transcend.io
|
|
1119
|
+
```
|
|
1120
|
+
|
|
1121
|
+
Delete all API keys with a certain title.
|
|
1122
|
+
|
|
1123
|
+
```sh
|
|
1124
|
+
yarn tr-generate-api-keys --email=test@transcend.io --password=$TRANSCEND_PASSWORD \
|
|
1125
|
+
--scopes="View Email Templates,View Data Map" --apiKeyTitle="CLI Usage Cross Instance Sync" -file=./working/auth.json \
|
|
1126
|
+
--createNewApiKey=false
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
Throw error if an API key already exists with that title, default behavior is to delete the existing API key and create a new one with that same title.
|
|
1130
|
+
|
|
1131
|
+
```sh
|
|
1132
|
+
yarn tr-generate-api-keys --email=test@transcend.io --password=$TRANSCEND_PASSWORD \
|
|
1133
|
+
--scopes="View Email Templates,View Data Map" --apiKeyTitle="CLI Usage Cross Instance Sync" -file=./working/auth.json \
|
|
1134
|
+
--deleteExistingApiKey=false
|
|
1135
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ScopeName } from '@transcend-io/privacy-types';
|
|
2
|
+
import { StoredApiKey } from '../codecs';
|
|
3
|
+
export interface ApiKeyGenerateError {
|
|
4
|
+
/** Name of instance */
|
|
5
|
+
organizationName: string;
|
|
6
|
+
/** Error */
|
|
7
|
+
error: string;
|
|
8
|
+
/** Organization ID API key is for */
|
|
9
|
+
organizationId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Generate API keys across multiple transcend accounts
|
|
13
|
+
*
|
|
14
|
+
* @param options - Options
|
|
15
|
+
* @returns Number of API keys created
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateCrossAccountApiKeys({ email, password, scopes, apiKeyTitle, deleteExistingApiKey, createNewApiKey, transcendUrl, }: {
|
|
18
|
+
/** Email address of user generating API keys */
|
|
19
|
+
email: string;
|
|
20
|
+
/** Password of user generating API keys */
|
|
21
|
+
password: string;
|
|
22
|
+
/** Title of the API create to create */
|
|
23
|
+
apiKeyTitle: string;
|
|
24
|
+
/** Title of the API create to create */
|
|
25
|
+
scopes: ScopeName[];
|
|
26
|
+
/** API URL for Transcend backend */
|
|
27
|
+
transcendUrl?: string;
|
|
28
|
+
/** When true delete existing API keys with that title, if set to false an API key exists with that title, an error is thrown */
|
|
29
|
+
deleteExistingApiKey?: boolean;
|
|
30
|
+
/** When true, generate new API keys, otherwise only will delete past API keys */
|
|
31
|
+
createNewApiKey?: boolean;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
/** Successfully generated */
|
|
34
|
+
apiKeys: StoredApiKey[];
|
|
35
|
+
/** Error results */
|
|
36
|
+
errors: ApiKeyGenerateError[];
|
|
37
|
+
}>;
|
|
38
|
+
//# sourceMappingURL=generateCrossAccountApiKeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCrossAccountApiKeys.d.ts","sourceRoot":"","sources":["../../src/api-keys/generateCrossAccountApiKeys.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,WAAW,mBAAmB;IAClC,uBAAuB;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,EAChD,KAAK,EACL,QAAQ,EACR,MAAM,EACN,WAAW,EACX,oBAA2B,EAC3B,eAAsB,EACtB,YAAyC,GAC1C,EAAE;IACD,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,oCAAoC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gIAAgI;IAChI,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iFAAiF;IACjF,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,OAAO,CAAC;IACV,6BAA6B;IAC7B,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,oBAAoB;IACpB,MAAM,EAAE,mBAAmB,EAAE,CAAC;CAC/B,CAAC,CA8HD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateCrossAccountApiKeys = void 0;
|
|
7
|
+
const bluebird_1 = require("bluebird");
|
|
8
|
+
const graphql_1 = require("../graphql");
|
|
9
|
+
const colors_1 = __importDefault(require("colors"));
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
/**
|
|
12
|
+
* Generate API keys across multiple transcend accounts
|
|
13
|
+
*
|
|
14
|
+
* @param options - Options
|
|
15
|
+
* @returns Number of API keys created
|
|
16
|
+
*/
|
|
17
|
+
async function generateCrossAccountApiKeys({ email, password, scopes, apiKeyTitle, deleteExistingApiKey = true, createNewApiKey = true, transcendUrl = 'https://api.transcend.io', }) {
|
|
18
|
+
// Create GraphQL client
|
|
19
|
+
const client = await (0, graphql_1.buildTranscendGraphQLClientGeneric)(transcendUrl, {});
|
|
20
|
+
// Login the user
|
|
21
|
+
logger_1.logger.info(colors_1.default.magenta('Logging in using email and password.'));
|
|
22
|
+
const { roles, loginCookie } = await (0, graphql_1.loginUser)(client, { email, password });
|
|
23
|
+
logger_1.logger.info(colors_1.default.green(`Successfully logged in and found ${roles.length} role${roles.length === 1 ? '' : 's'}!`));
|
|
24
|
+
// Save cookie to call route subsequent times
|
|
25
|
+
client.setHeaders({
|
|
26
|
+
Cookie: loginCookie,
|
|
27
|
+
});
|
|
28
|
+
// Save the resulting API keys
|
|
29
|
+
const results = [];
|
|
30
|
+
const errors = [];
|
|
31
|
+
// Generate API keys
|
|
32
|
+
logger_1.logger.info(colors_1.default.magenta(`Generating API keys with title: ${apiKeyTitle}, scopes: ${scopes.join(',')}.`));
|
|
33
|
+
// Map over each role
|
|
34
|
+
await (0, bluebird_1.mapSeries)(roles, async (role) => {
|
|
35
|
+
try {
|
|
36
|
+
// Log into the other instance
|
|
37
|
+
await (0, graphql_1.assumeRole)(client, { roleId: role.id, email });
|
|
38
|
+
// Grab API keys with that title
|
|
39
|
+
logger_1.logger.info(colors_1.default.magenta(`Checking if API key already exists in organization "${role.organization.name}" with title: "${apiKeyTitle}".`));
|
|
40
|
+
// Delete existing API key
|
|
41
|
+
const [apiKeyWithTitle] = await (0, graphql_1.fetchAllApiKeys)(client, [apiKeyTitle]);
|
|
42
|
+
if (apiKeyWithTitle && deleteExistingApiKey) {
|
|
43
|
+
logger_1.logger.info(colors_1.default.yellow(`Deleting existing API key in "${role.organization.name}" with title: "${apiKeyTitle}".`));
|
|
44
|
+
await (0, graphql_1.deleteApiKey)(client, apiKeyWithTitle.id);
|
|
45
|
+
logger_1.logger.info(colors_1.default.green(`Successfully deleted API key in "${role.organization.name}" with title: "${apiKeyTitle}".`));
|
|
46
|
+
}
|
|
47
|
+
else if (apiKeyWithTitle) {
|
|
48
|
+
// throw error if one exists but not configured to delete
|
|
49
|
+
throw new Error(`API key already exists with title: "${apiKeyTitle}"`);
|
|
50
|
+
}
|
|
51
|
+
// Create the API key
|
|
52
|
+
if (createNewApiKey) {
|
|
53
|
+
logger_1.logger.info(colors_1.default.magenta(`Creating API key in "${role.organization.name}" with title: "${apiKeyTitle}".`));
|
|
54
|
+
const { apiKey } = await (0, graphql_1.createApiKey)(client, {
|
|
55
|
+
title: apiKeyTitle,
|
|
56
|
+
scopes,
|
|
57
|
+
});
|
|
58
|
+
results.push({
|
|
59
|
+
organizationName: role.organization.name,
|
|
60
|
+
organizationId: role.organization.id,
|
|
61
|
+
apiKey,
|
|
62
|
+
});
|
|
63
|
+
logger_1.logger.info(colors_1.default.green(`Successfully created API key in "${role.organization.name}" with title: "${apiKeyTitle}".`));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// Delete only
|
|
67
|
+
results.push({
|
|
68
|
+
organizationName: role.organization.name,
|
|
69
|
+
organizationId: role.organization.id,
|
|
70
|
+
apiKey: '',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
logger_1.logger.error(colors_1.default.red(`Failed to create API key in organization "${role.organization.name}"! - ${err.message}`));
|
|
76
|
+
errors.push({
|
|
77
|
+
organizationName: role.organization.name,
|
|
78
|
+
organizationId: role.organization.id,
|
|
79
|
+
error: err.message,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
logger_1.logger.info(colors_1.default.green(`Successfully created ${results.length} API key${results.length === 1 ? '' : 's'}`));
|
|
84
|
+
if (errors.length > 0) {
|
|
85
|
+
logger_1.logger.error(colors_1.default.red(`Failed to create ${errors.length} API key${errors.length === 1 ? '' : 's'}!`));
|
|
86
|
+
}
|
|
87
|
+
return { errors, apiKeys: results };
|
|
88
|
+
}
|
|
89
|
+
exports.generateCrossAccountApiKeys = generateCrossAccountApiKeys;
|
|
90
|
+
//# sourceMappingURL=generateCrossAccountApiKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateCrossAccountApiKeys.js","sourceRoot":"","sources":["../../src/api-keys/generateCrossAccountApiKeys.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAqC;AACrC,wCAOoB;AAEpB,oDAA4B;AAE5B,sCAAmC;AAWnC;;;;;GAKG;AACI,KAAK,UAAU,2BAA2B,CAAC,EAChD,KAAK,EACL,QAAQ,EACR,MAAM,EACN,WAAW,EACX,oBAAoB,GAAG,IAAI,EAC3B,eAAe,GAAG,IAA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B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./generateCrossAccountApiKeys"), exports);
|
|
14
|
+
__exportStar(require("./validateTranscendAuth"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api-keys/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gEAA8C;AAC9C,0DAAwC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StoredApiKey } from '../codecs';
|
|
2
|
+
/**
|
|
3
|
+
* Determine if the `--auth` parameter is an API key or a path to a JSON
|
|
4
|
+
* file containing a list of API keys.
|
|
5
|
+
*
|
|
6
|
+
* @param auth - Raw auth parameter
|
|
7
|
+
* @returns The API key or the list API keys
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateTranscendAuth(auth: string): string | StoredApiKey[];
|
|
10
|
+
//# sourceMappingURL=validateTranscendAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTranscendAuth.d.ts","sourceRoot":"","sources":["../../src/api-keys/validateTranscendAuth.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,EAAE,CAmB3E"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.validateTranscendAuth = void 0;
|
|
26
|
+
const type_utils_1 = require("@transcend-io/type-utils");
|
|
27
|
+
const colors_1 = __importDefault(require("colors"));
|
|
28
|
+
const t = __importStar(require("io-ts"));
|
|
29
|
+
const logger_1 = require("../logger");
|
|
30
|
+
const fs_1 = require("fs");
|
|
31
|
+
const codecs_1 = require("../codecs");
|
|
32
|
+
/**
|
|
33
|
+
* Determine if the `--auth` parameter is an API key or a path to a JSON
|
|
34
|
+
* file containing a list of API keys.
|
|
35
|
+
*
|
|
36
|
+
* @param auth - Raw auth parameter
|
|
37
|
+
* @returns The API key or the list API keys
|
|
38
|
+
*/
|
|
39
|
+
function validateTranscendAuth(auth) {
|
|
40
|
+
// Ensure auth is passed
|
|
41
|
+
if (!auth) {
|
|
42
|
+
logger_1.logger.error(colors_1.default.red('A Transcend API key must be provided. You can specify using --auth=asd123'));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
// Read from disk
|
|
46
|
+
if ((0, fs_1.existsSync)(auth)) {
|
|
47
|
+
// validate that file is a list of API keys
|
|
48
|
+
return (0, type_utils_1.decodeCodec)(t.array(codecs_1.StoredApiKey), (0, fs_1.readFileSync)(auth, 'utf-8'));
|
|
49
|
+
}
|
|
50
|
+
// Return as single API key
|
|
51
|
+
return auth;
|
|
52
|
+
}
|
|
53
|
+
exports.validateTranscendAuth = validateTranscendAuth;
|
|
54
|
+
//# sourceMappingURL=validateTranscendAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTranscendAuth.js","sourceRoot":"","sources":["../../src/api-keys/validateTranscendAuth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAuD;AACvD,oDAA4B;AAC5B,yCAA2B;AAC3B,sCAAmC;AACnC,2BAA8C;AAC9C,sCAAyC;AAEzC;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,IAAY;IAChD,wBAAwB;IACxB,IAAI,CAAC,IAAI,EAAE;QACT,eAAM,CAAC,KAAK,CACV,gBAAM,CAAC,GAAG,CACR,2EAA2E,CAC5E,CACF,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,iBAAiB;IACjB,IAAI,IAAA,eAAU,EAAC,IAAI,CAAC,EAAE;QACpB,2CAA2C;QAC3C,OAAO,IAAA,wBAAW,EAAC,CAAC,CAAC,KAAK,CAAC,qBAAY,CAAC,EAAE,IAAA,iBAAY,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;KACxE;IAED,2BAA2B;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC;AAnBD,sDAmBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-generate-cross-account-api-keys.d.ts","sourceRoot":"","sources":["../src/cli-generate-cross-account-api-keys.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
8
|
+
const colors_1 = __importDefault(require("colors"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const keyBy_1 = __importDefault(require("lodash/keyBy"));
|
|
11
|
+
const privacy_types_1 = require("@transcend-io/privacy-types");
|
|
12
|
+
const logger_1 = require("./logger");
|
|
13
|
+
const api_keys_1 = require("./api-keys");
|
|
14
|
+
const SCOPES_BY_TITLE = (0, keyBy_1.default)(Object.entries(privacy_types_1.TRANSCEND_SCOPES).map(([name, value]) => ({
|
|
15
|
+
...value,
|
|
16
|
+
name,
|
|
17
|
+
})), 'title');
|
|
18
|
+
const SCOPE_TITLES = Object.keys(SCOPES_BY_TITLE);
|
|
19
|
+
/**
|
|
20
|
+
* Create API keys with the same set of scopes across multiple Transcend instances
|
|
21
|
+
*
|
|
22
|
+
* Requires the username and password of user with access to multiple instances.
|
|
23
|
+
*
|
|
24
|
+
* Dev Usage:
|
|
25
|
+
* yarn ts-node ./src/cli-generate-cross-account-api-keys.ts --email=test@transcend.io --email=NE8pGp$s8Gm4Mzb5 \
|
|
26
|
+
* --apiKeyTitle="My Test Key" --scopes="View Email Templates,View Data Map" --file=./secrets.json
|
|
27
|
+
*
|
|
28
|
+
* Standard usage:
|
|
29
|
+
* yarn tr-generate-api-keys --email=test@transcend.io --password=NE8pGp$s8Gm4Mzb5 \
|
|
30
|
+
* --apiKeyTitle="My Test Key" --scopes="View Email Templates,View Data Map" --file=./secrets.json
|
|
31
|
+
*/
|
|
32
|
+
async function main() {
|
|
33
|
+
// Parse command line arguments
|
|
34
|
+
const { transcendUrl = 'https://api.transcend.io', file, email, password, apiKeyTitle, scopes, deleteExistingApiKey = 'true', createNewApiKey = 'true', } = (0, yargs_parser_1.default)(process.argv.slice(2));
|
|
35
|
+
// Ensure file is passed
|
|
36
|
+
if (!file) {
|
|
37
|
+
logger_1.logger.error(colors_1.default.red('A file must be provided. You can specify using --file=./secrets.json'));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
// Ensure email is passed
|
|
41
|
+
if (!email) {
|
|
42
|
+
logger_1.logger.error(colors_1.default.red('An email must be provided. You can specify using --email=asd123@test.com'));
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
// Ensure password is passed
|
|
46
|
+
if (!password) {
|
|
47
|
+
logger_1.logger.error(colors_1.default.red('A password must be provided. You can specify using --password=asd123'));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
// Ensure apiKeyTitle is passed
|
|
51
|
+
if (!apiKeyTitle) {
|
|
52
|
+
logger_1.logger.error(colors_1.default.red('An API key title must be provided. You can specify using --apiKeyTitle="My Title"'));
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
// Ensure scopes is passed
|
|
56
|
+
if (!scopes) {
|
|
57
|
+
logger_1.logger.error(colors_1.default.red('Scopes must be provided. You can specify using --scopes="View Email Templates,View Data Map". ' +
|
|
58
|
+
`Expected one of: \n${SCOPE_TITLES.join('\n')}`));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
// Validate scopes
|
|
62
|
+
const splitScopes = scopes.split(',').map((x) => x.trim());
|
|
63
|
+
const invalidScopes = splitScopes.filter((scopeTitle) => !SCOPES_BY_TITLE[scopeTitle]);
|
|
64
|
+
if (invalidScopes.length > 0) {
|
|
65
|
+
logger_1.logger.error(colors_1.default.red(`Failed to parse scopes:"${invalidScopes.join(',')}".\n` +
|
|
66
|
+
`Expected one of: \n${SCOPE_TITLES.join('\n')}`));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const scopeNames = splitScopes.map((scopeTitle) => SCOPES_BY_TITLE[scopeTitle].name);
|
|
70
|
+
// Upload privacy requests
|
|
71
|
+
const { errors, apiKeys } = await (0, api_keys_1.generateCrossAccountApiKeys)({
|
|
72
|
+
transcendUrl,
|
|
73
|
+
password,
|
|
74
|
+
email,
|
|
75
|
+
deleteExistingApiKey: deleteExistingApiKey !== 'false',
|
|
76
|
+
createNewApiKey: createNewApiKey !== 'false',
|
|
77
|
+
apiKeyTitle,
|
|
78
|
+
scopes: scopeNames,
|
|
79
|
+
});
|
|
80
|
+
// Write to disk
|
|
81
|
+
(0, fs_1.writeFileSync)(file, `${JSON.stringify(apiKeys, null, 2)}\n`);
|
|
82
|
+
if (errors.length > 0) {
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
main();
|
|
87
|
+
//# sourceMappingURL=cli-generate-cross-account-api-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-generate-cross-account-api-keys.js","sourceRoot":"","sources":["../src/cli-generate-cross-account-api-keys.ts"],"names":[],"mappings":";;;;;;AAEA,gEAAiC;AACjC,oDAA4B;AAC5B,2BAAmC;AACnC,yDAAiC;AACjC,+DAA0E;AAE1E,qCAAkC;AAClC,yCAAyD;AAEzD,MAAM,eAAe,GAAG,IAAA,eAAK,EAC3B,MAAM,CAAC,OAAO,CAAC,gCAAgB,CAAC,CAAC,GAAG,CAAC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AE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IAC7D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/build/cli-push.js
CHANGED
|
@@ -6,12 +6,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const yargs_parser_1 = __importDefault(require("yargs-parser"));
|
|
8
8
|
const logger_1 = require("./logger");
|
|
9
|
+
const bluebird_1 = require("bluebird");
|
|
9
10
|
const fs_1 = require("fs");
|
|
10
11
|
const readTranscendYaml_1 = require("./readTranscendYaml");
|
|
11
12
|
const colors_1 = __importDefault(require("colors"));
|
|
12
13
|
const graphql_1 = require("./graphql");
|
|
13
14
|
const constants_1 = require("./constants");
|
|
15
|
+
const api_keys_1 = require("./api-keys");
|
|
14
16
|
const mergeTranscendInputs_1 = require("./mergeTranscendInputs");
|
|
17
|
+
/**
|
|
18
|
+
* Sync configuration to Transcend
|
|
19
|
+
*
|
|
20
|
+
* @param options - Options
|
|
21
|
+
* @returns True if synced successfully, false if error occurs
|
|
22
|
+
*/
|
|
23
|
+
async function syncConfiguration({ transcendUrl, auth, pageSize, publishToPrivacyCenter, contents, }) {
|
|
24
|
+
const client = (0, graphql_1.buildTranscendGraphQLClient)(transcendUrl, auth);
|
|
25
|
+
// Sync to Transcend
|
|
26
|
+
try {
|
|
27
|
+
const encounteredError = await (0, graphql_1.syncConfigurationToTranscend)(contents, client, { pageSize, publishToPrivacyCenter });
|
|
28
|
+
return !encounteredError;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
logger_1.logger.error(colors_1.default.red(`An unexpected error occurred syncing the schema: ${err.message}`));
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
15
36
|
/**
|
|
16
37
|
* Push the transcend.yml file remotely into a Transcend instance
|
|
17
38
|
*
|
|
@@ -23,12 +44,9 @@ const mergeTranscendInputs_1 = require("./mergeTranscendInputs");
|
|
|
23
44
|
*/
|
|
24
45
|
async function main() {
|
|
25
46
|
// Parse command line arguments
|
|
26
|
-
const { file = './transcend.yml', transcendUrl = 'https://api.transcend.io', auth, variables = '', pageSize = '', } = (0, yargs_parser_1.default)(process.argv.slice(2));
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
logger_1.logger.error(colors_1.default.red('A Transcend API key must be provided. You can specify using --auth=asd123'));
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
47
|
+
const { file = './transcend.yml', transcendUrl = 'https://api.transcend.io', auth, variables = '', pageSize = '', publishToPrivacyCenter, } = (0, yargs_parser_1.default)(process.argv.slice(2));
|
|
48
|
+
// Parse authentication as API key or path to list of API keys
|
|
49
|
+
const apiKeyOrList = await (0, api_keys_1.validateTranscendAuth)(auth);
|
|
32
50
|
// Parse out the variables
|
|
33
51
|
const splitVars = variables.split(',').filter((x) => !!x);
|
|
34
52
|
const vars = {};
|
|
@@ -66,19 +84,47 @@ async function main() {
|
|
|
66
84
|
});
|
|
67
85
|
const [base, ...rest] = transcendInputs;
|
|
68
86
|
const contents = (0, mergeTranscendInputs_1.mergeTranscendInputs)(base, ...rest);
|
|
69
|
-
//
|
|
70
|
-
const
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
87
|
+
// Parse page size
|
|
88
|
+
const parsedPageSize = pageSize ? parseInt(pageSize, 10) : 50;
|
|
89
|
+
// process a single API key
|
|
90
|
+
if (typeof apiKeyOrList === 'string') {
|
|
91
|
+
const success = await syncConfiguration({
|
|
92
|
+
transcendUrl,
|
|
93
|
+
auth: apiKeyOrList,
|
|
94
|
+
contents,
|
|
95
|
+
publishToPrivacyCenter: publishToPrivacyCenter === 'true',
|
|
96
|
+
pageSize: parsedPageSize,
|
|
97
|
+
});
|
|
98
|
+
// exist with error code
|
|
99
|
+
if (!success) {
|
|
75
100
|
logger_1.logger.info(colors_1.default.red(`Sync encountered errors. View output above for more information, or check out ${constants_1.ADMIN_DASH_INTEGRATIONS}`));
|
|
76
101
|
process.exit(1);
|
|
77
102
|
}
|
|
78
103
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
104
|
+
else {
|
|
105
|
+
const encounteredErrors = [];
|
|
106
|
+
await (0, bluebird_1.mapSeries)(apiKeyOrList, async (apiKey, ind) => {
|
|
107
|
+
const prefix = `[${ind}/${apiKeyOrList.length}][${apiKey.organizationName}] `;
|
|
108
|
+
logger_1.logger.info(colors_1.default.magenta(`~~~\n\n${prefix}Attempting to push configuration...\n\n~~~`));
|
|
109
|
+
const success = await syncConfiguration({
|
|
110
|
+
transcendUrl,
|
|
111
|
+
auth: apiKey.apiKey,
|
|
112
|
+
contents,
|
|
113
|
+
pageSize: parsedPageSize,
|
|
114
|
+
publishToPrivacyCenter: publishToPrivacyCenter === 'true',
|
|
115
|
+
});
|
|
116
|
+
if (success) {
|
|
117
|
+
logger_1.logger.info(colors_1.default.green(`${prefix}Successfully pushed configuration!`));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
logger_1.logger.error(colors_1.default.red(`${prefix}Failed to sync configuration.`));
|
|
121
|
+
encounteredErrors.push(apiKey.organizationName);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
if (encounteredErrors.length > 0) {
|
|
125
|
+
logger_1.logger.info(colors_1.default.red(`Sync encountered errors for "${encounteredErrors.join(',')}". View output above for more information, or check out ${constants_1.ADMIN_DASH_INTEGRATIONS}`));
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
82
128
|
}
|
|
83
129
|
// Indicate success
|
|
84
130
|
logger_1.logger.info(colors_1.default.green(`Successfully synced yaml file to Transcend! View at ${constants_1.ADMIN_DASH_INTEGRATIONS}`));
|
package/build/cli-push.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-push.js","sourceRoot":"","sources":["../src/cli-push.ts"],"names":[],"mappings":";;;;;;AAEA,gEAAiC;AACjC,qCAAkC;AAClC,2BAAgC;AAChC,2DAAwD;AACxD,oDAA4B;AAC5B,uCAGmB;AAEnB,2CAAsD;
|
|
1
|
+
{"version":3,"file":"cli-push.js","sourceRoot":"","sources":["../src/cli-push.ts"],"names":[],"mappings":";;;;;;AAEA,gEAAiC;AACjC,qCAAkC;AAClC,uCAAqC;AACrC,2BAAgC;AAChC,2DAAwD;AACxD,oDAA4B;AAC5B,uCAGmB;AAEnB,2CAAsD;AAGtD,yCAAmD;AACnD,iEAA8D;AAE9D;;;;;GAKG;AACH,KAAK,UAAU,iBAAiB,CAAC,EAC/B,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,sBAAsB,EACtB,QAAQ,GAYT;IACC,MAAM,MAAM,GAAG,IAAA,qCAA2B,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE/D,oBAAoB;IACpB,IAAI;QACF,MAAM,gBAAgB,GAAG,MAAM,IAAA,sCAA4B,EACzD,QAAQ,EACR,MAAM,EACN,EAAE,QAAQ,EAAE,sBAAsB,EAAE,CACrC,CAAC;QACF,OAAO,CAAC,gBAAgB,CAAC;QACzB,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,GAAG,EAAE;QACZ,eAAM,CAAC,KAAK,CACV,gBAAM,CAAC,GAAG,CACR,oDAAoD,GAAG,CAAC,OAAO,EAAE,CAClE,CACF,CAAC;QACF,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,IAAI;IACjB,+BAA+B;IAC/B,MAAM,EACJ,IAAI,GAAG,iBAAiB,EACxB,YAAY,GAAG,0BAA0B,EACzC,IAAI,EACJ,SAAS,GAAG,EAAE,EACd,QAAQ,GAAG,EAAE,EACb,sBAAsB,GACvB,GAAG,IAAA,sBAAK,EAAC,OAAO,CAAC,IA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AI,GAAG,IAAI,YAAY,CAAC,MAAM,KAAK,MAAM,CAAC,gBAAgB,IAAI,CAAC;YAC9E,eAAM,CAAC,IAAI,CACT,gBAAM,CAAC,OAAO,CACZ,UAAU,MAAM,4CAA4C,CAC7D,CACF,CAAC;YAEF,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC;gBACtC,YAAY;gBACZ,IAAI,EAAE,MAAM,CAAC,MAAM;gBACnB,QAAQ;gBACR,QAAQ,EAAE,cAAc;gBACxB,sBAAsB,EAAE,sBAAsB,KAAK,MAAM;aAC1D,CAAC,CAAC;YAEH,IAAI,OAAO,EAAE;gBACX,eAAM,CAAC,IAAI,CACT,gBAAM,CAAC,KAAK,CAAC,GAAG,MAAM,oCAAoC,CAAC,CAC5D,CAAC;aACH;iBAAM;gBACL,eAAM,CAAC,KAAK,CAAC,gBAAM,CAAC,GAAG,CAAC,GAAG,MAAM,+BAA+B,CAAC,CAAC,CAAC;gBACnE,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;aACjD;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;YAChC,eAAM,CAAC,IAAI,CACT,gBAAM,CAAC,GAAG,CACR,gCAAgC,iBAAiB,CAAC,IAAI,CACpD,GAAG,CACJ,2DAA2D,mCAAuB,EAAE,CACtF,CACF,CAAC;YAEF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;IAED,mBAAmB;IACnB,eAAM,CAAC,IAAI,CACT,gBAAM,CAAC,KAAK,CACV,uDAAuD,mCAAuB,EAAE,CACjF,CACF,CAAC;AACJ,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/build/codecs.d.ts
CHANGED
|
@@ -12516,4 +12516,17 @@ export declare const TranscendInput: t.PartialC<{
|
|
|
12516
12516
|
}>;
|
|
12517
12517
|
/** Type override */
|
|
12518
12518
|
export declare type TranscendInput = t.TypeOf<typeof TranscendInput>;
|
|
12519
|
+
/**
|
|
12520
|
+
* The output of `tr-generate-api-keys` that can be provided to `tr-push`
|
|
12521
|
+
*/
|
|
12522
|
+
export declare const StoredApiKey: t.TypeC<{
|
|
12523
|
+
/** Name of instance */
|
|
12524
|
+
organizationName: t.StringC;
|
|
12525
|
+
/** API key */
|
|
12526
|
+
apiKey: t.StringC;
|
|
12527
|
+
/** Organization ID API key is for */
|
|
12528
|
+
organizationId: t.StringC;
|
|
12529
|
+
}>;
|
|
12530
|
+
/** Type override */
|
|
12531
|
+
export declare type StoredApiKey = t.TypeOf<typeof StoredApiKey>;
|
|
12519
12532
|
//# sourceMappingURL=codecs.d.ts.map
|