@transcend-io/cli 4.131.0 → 4.132.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.
@@ -0,0 +1,104 @@
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.syncTeams = exports.updateTeam = exports.createTeam = void 0;
7
+ const bluebird_1 = require("bluebird");
8
+ const gqls_1 = require("./gqls");
9
+ const logger_1 = require("../logger");
10
+ const keyBy_1 = __importDefault(require("lodash/keyBy"));
11
+ const makeGraphQLRequest_1 = require("./makeGraphQLRequest");
12
+ const colors_1 = __importDefault(require("colors"));
13
+ const fetchAllTeams_1 = require("./fetchAllTeams");
14
+ /**
15
+ * Input to create a new team
16
+ *
17
+ * @param client - GraphQL client
18
+ * @param team - Input
19
+ */
20
+ async function createTeam(client, team) {
21
+ const input = {
22
+ name: team.name,
23
+ description: team.description,
24
+ ssoTitle: team['sso-title'],
25
+ ssoDepartment: team['sso-department'],
26
+ ssoGroup: team['sso-group'],
27
+ scopes: team.scopes,
28
+ userEmails: team.users,
29
+ };
30
+ const { createTeam } = await (0, makeGraphQLRequest_1.makeGraphQLRequest)(client, gqls_1.CREATE_TEAM, {
31
+ input,
32
+ });
33
+ return createTeam.team;
34
+ }
35
+ exports.createTeam = createTeam;
36
+ /**
37
+ * Input to update teams
38
+ *
39
+ * @param client - GraphQL client
40
+ * @param input - Team input to update
41
+ * @param teamId - ID of team
42
+ */
43
+ async function updateTeam(client, input, teamId) {
44
+ const { updateTeam } = await (0, makeGraphQLRequest_1.makeGraphQLRequest)(client, gqls_1.UPDATE_TEAM, {
45
+ input: {
46
+ id: teamId,
47
+ name: input.name,
48
+ description: input.description,
49
+ ssoTitle: input['sso-title'],
50
+ ssoDepartment: input['sso-department'],
51
+ ssoGroup: input['sso-group'],
52
+ scopes: input.scopes,
53
+ userEmails: input.users,
54
+ },
55
+ });
56
+ return updateTeam.team;
57
+ }
58
+ exports.updateTeam = updateTeam;
59
+ /**
60
+ * Sync the teams
61
+ *
62
+ * @param client - GraphQL client
63
+ * @param inputs - Inputs to create
64
+ * @returns True if run without error, returns false if an error occurred
65
+ */
66
+ async function syncTeams(client, inputs) {
67
+ // Fetch existing
68
+ logger_1.logger.info(colors_1.default.magenta(`Syncing "${inputs.length}" teams...`));
69
+ let encounteredError = false;
70
+ // Fetch existing
71
+ const existingTeams = await (0, fetchAllTeams_1.fetchAllTeams)(client);
72
+ // Look up by name
73
+ const teamsByName = (0, keyBy_1.default)(existingTeams, 'name');
74
+ // Create new teams
75
+ const newTeams = inputs.filter((input) => !teamsByName[input.name]);
76
+ const updatedTeams = inputs.filter((input) => !!teamsByName[input.name]);
77
+ // Create new teams
78
+ await (0, bluebird_1.mapSeries)(newTeams, async (team) => {
79
+ try {
80
+ const newTeam = await createTeam(client, team);
81
+ teamsByName[newTeam.name] = newTeam;
82
+ logger_1.logger.info(colors_1.default.green(`Successfully created team "${team.name}"!`));
83
+ }
84
+ catch (err) {
85
+ encounteredError = true;
86
+ logger_1.logger.info(colors_1.default.red(`Failed to sync team "${team.name}"! - ${err.message}`));
87
+ }
88
+ });
89
+ // Update all teams
90
+ await (0, bluebird_1.mapSeries)(updatedTeams, async (input) => {
91
+ try {
92
+ const newTeam = await updateTeam(client, input, teamsByName[input.name].id);
93
+ teamsByName[newTeam.name] = newTeam;
94
+ logger_1.logger.info(colors_1.default.green(`Successfully updated team "${input.name}"!`));
95
+ }
96
+ catch (err) {
97
+ encounteredError = true;
98
+ logger_1.logger.info(colors_1.default.red(`Failed to sync team "${input.name}"! - ${err.message}`));
99
+ }
100
+ });
101
+ return !encounteredError;
102
+ }
103
+ exports.syncTeams = syncTeams;
104
+ //# sourceMappingURL=syncTeams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syncTeams.js","sourceRoot":"","sources":["../../src/graphql/syncTeams.ts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