great 0.3.2 → 1.0.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.
- package/README.md +119 -13
- package/dist/accounts/create.d.ts +4 -0
- package/dist/accounts/create.js +42 -0
- package/dist/accounts/create.js.map +1 -0
- package/dist/accounts/index.d.ts +5 -2
- package/dist/accounts/index.js +48 -9
- package/dist/accounts/index.js.map +1 -1
- package/dist/clone/index.d.ts +8 -0
- package/dist/clone/index.js +61 -0
- package/dist/clone/index.js.map +1 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.js +111 -0
- package/dist/config/index.js.map +1 -0
- package/dist/create/index.d.ts +3 -0
- package/dist/create/index.js +7 -0
- package/dist/create/index.js.map +1 -0
- package/dist/deploy/index.d.ts +11 -0
- package/dist/deploy/index.js +132 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/explode/index.d.ts +5 -0
- package/dist/explode/index.js +32 -0
- package/dist/explode/index.js.map +1 -0
- package/dist/explode/transform.d.ts +30 -0
- package/dist/explode/transform.js +100 -0
- package/dist/explode/transform.js.map +1 -0
- package/dist/explode/unescapeMongo.d.ts +1 -0
- package/dist/explode/unescapeMongo.js +15 -0
- package/dist/explode/unescapeMongo.js.map +1 -0
- package/dist/generated/graphql.d.ts +1784 -0
- package/dist/generated/graphql.js +73 -0
- package/dist/generated/graphql.js.map +1 -0
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/dist/init/index.d.ts +5 -0
- package/dist/init/index.js +46 -0
- package/dist/init/index.js.map +1 -0
- package/dist/integrations/create.d.ts +6 -0
- package/dist/integrations/create.js +70 -0
- package/dist/integrations/create.js.map +1 -0
- package/dist/{projects/describe.d.ts → integrations/index.d.ts} +0 -1
- package/dist/integrations/index.js +23 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/list.d.ts +7 -0
- package/dist/integrations/list.js +103 -0
- package/dist/integrations/list.js.map +1 -0
- package/dist/login/index.d.ts +6 -0
- package/dist/login/index.js +25 -0
- package/dist/login/index.js.map +1 -0
- package/dist/logout/index.d.ts +6 -0
- package/dist/logout/index.js +11 -0
- package/dist/logout/index.js.map +1 -0
- package/dist/now/index.d.ts +3 -1
- package/dist/now/index.js +11 -2
- package/dist/now/index.js.map +1 -1
- package/dist/pull/index.d.ts +5 -1
- package/dist/pull/index.js +50 -19
- package/dist/pull/index.js.map +1 -1
- package/dist/push/index.d.ts +11 -0
- package/dist/push/index.js +481 -0
- package/dist/push/index.js.map +1 -0
- package/dist/repl/dispatch.d.ts +8 -0
- package/dist/repl/dispatch.js +75 -0
- package/dist/repl/dispatch.js.map +1 -0
- package/dist/repl/help.d.ts +2 -0
- package/dist/repl/help.js +14 -0
- package/dist/repl/help.js.map +1 -0
- package/dist/repl/index.d.ts +10 -0
- package/dist/repl/index.js +92 -0
- package/dist/repl/index.js.map +1 -0
- package/dist/run/index.d.ts +33 -1
- package/dist/run/index.js +109 -40
- package/dist/run/index.js.map +1 -1
- package/dist/status/index.d.ts +10 -0
- package/dist/status/index.js +122 -0
- package/dist/status/index.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/authServer.d.ts +4 -0
- package/dist/utils/authServer.js +49 -0
- package/dist/utils/authServer.js.map +1 -0
- package/dist/utils/config.d.ts +15 -0
- package/dist/utils/config.js +41 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/createIntegrationFromFile.d.ts +22 -0
- package/dist/utils/createIntegrationFromFile.js +116 -0
- package/dist/utils/createIntegrationFromFile.js.map +1 -0
- package/dist/utils/determineNameAndKey.d.ts +4 -0
- package/dist/utils/determineNameAndKey.js +8 -0
- package/dist/utils/determineNameAndKey.js.map +1 -0
- package/dist/utils/dispatch.d.ts +3 -0
- package/dist/utils/dispatch.js +37 -0
- package/dist/utils/dispatch.js.map +1 -0
- package/dist/utils/fetchLocal.d.ts +3 -0
- package/dist/utils/fetchLocal.js +21 -0
- package/dist/utils/fetchLocal.js.map +1 -0
- package/dist/utils/fetchSession.d.ts +7 -0
- package/dist/utils/fetchSession.js +34 -0
- package/dist/utils/fetchSession.js.map +1 -0
- package/dist/utils/graphqlClient.d.ts +10 -0
- package/dist/utils/graphqlClient.js +24 -0
- package/dist/utils/graphqlClient.js.map +1 -0
- package/dist/utils/graphqlError.d.ts +2 -0
- package/dist/utils/graphqlError.js +20 -0
- package/dist/utils/graphqlError.js.map +1 -0
- package/dist/utils/hashContent.d.ts +1 -0
- package/dist/utils/hashContent.js +7 -0
- package/dist/utils/hashContent.js.map +1 -0
- package/dist/utils/jwt.d.ts +6 -0
- package/dist/utils/jwt.js +24 -0
- package/dist/utils/jwt.js.map +1 -0
- package/dist/utils/promptForValue.d.ts +9 -0
- package/dist/utils/promptForValue.js +24 -0
- package/dist/utils/promptForValue.js.map +1 -0
- package/dist/utils/resolveAccount.d.ts +19 -0
- package/dist/utils/resolveAccount.js +75 -0
- package/dist/utils/resolveAccount.js.map +1 -0
- package/dist/utils/resolveElement.d.ts +20 -0
- package/dist/utils/resolveElement.js +67 -0
- package/dist/utils/resolveElement.js.map +1 -0
- package/dist/utils/resolveIntegration.d.ts +9 -0
- package/dist/utils/resolveIntegration.js +71 -0
- package/dist/utils/resolveIntegration.js.map +1 -0
- package/dist/utils/saveIntegration.d.ts +16 -0
- package/dist/utils/saveIntegration.js +117 -0
- package/dist/utils/saveIntegration.js.map +1 -0
- package/dist/utils/token.d.ts +6 -0
- package/dist/utils/token.js +31 -0
- package/dist/utils/token.js.map +1 -0
- package/dist/utils/valueTypes.d.ts +4 -0
- package/dist/utils/valueTypes.js +43 -0
- package/dist/utils/valueTypes.js.map +1 -0
- package/dist/value/get.d.ts +8 -0
- package/dist/value/get.js +50 -0
- package/dist/value/get.js.map +1 -0
- package/dist/{projects → value}/index.d.ts +1 -2
- package/dist/value/index.js +26 -0
- package/dist/value/index.js.map +1 -0
- package/dist/value/list.d.ts +8 -0
- package/dist/value/list.js +122 -0
- package/dist/value/list.js.map +1 -0
- package/dist/value/set.d.ts +12 -0
- package/dist/value/set.js +103 -0
- package/dist/value/set.js.map +1 -0
- package/dist/whoami/fetchSession.d.ts +9 -0
- package/dist/whoami/fetchSession.js +19 -0
- package/dist/whoami/fetchSession.js.map +1 -0
- package/dist/whoami/index.d.ts +9 -1
- package/dist/whoami/index.js +18 -10
- package/dist/whoami/index.js.map +1 -1
- package/package.json +29 -13
- package/.codeclimate.yml +0 -7
- package/.editorconfig +0 -11
- package/.nvmrc +0 -1
- package/.prettierrc.json +0 -6
- package/dist/now/index.test.d.ts +0 -1
- package/dist/now/index.test.js +0 -18
- package/dist/now/index.test.js.map +0 -1
- package/dist/projects/describe.js +0 -44
- package/dist/projects/describe.js.map +0 -1
- package/dist/projects/index.js +0 -39
- package/dist/projects/index.js.map +0 -1
- package/dist/utils/callApi.d.ts +0 -5
- package/dist/utils/callApi.js +0 -20
- package/dist/utils/callApi.js.map +0 -1
- package/dist/utils/fetchLocalProject.d.ts +0 -1
- package/dist/utils/fetchLocalProject.js +0 -12
- package/dist/utils/fetchLocalProject.js.map +0 -1
- package/dist/utils/saveProject.d.ts +0 -2
- package/dist/utils/saveProject.js +0 -68
- package/dist/utils/saveProject.js.map +0 -1
- package/eslint.config.js +0 -27
- package/src/accounts/index.ts +0 -41
- package/src/index.ts +0 -22
- package/src/now/index.test.ts +0 -31
- package/src/now/index.ts +0 -15
- package/src/projects/describe.ts +0 -80
- package/src/projects/index.ts +0 -61
- package/src/pull/index.ts +0 -45
- package/src/run/index.ts +0 -81
- package/src/utils/callApi.ts +0 -29
- package/src/utils/fetchLocalProject.ts +0 -12
- package/src/utils/saveProject.ts +0 -106
- package/src/whoami/index.ts +0 -32
- package/tsconfig.json +0 -28
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { sentenceCase } from 'change-case';
|
|
3
|
+
import { gql } from 'graphql-tag';
|
|
4
|
+
import { resolveAccountId } from './resolveAccount.js';
|
|
5
|
+
const CreateIntegrationMutationDocument = gql `
|
|
6
|
+
mutation CreateIntegrationFromFile(
|
|
7
|
+
$accountId: ID!
|
|
8
|
+
$name: String!
|
|
9
|
+
$key: ID
|
|
10
|
+
$description: String
|
|
11
|
+
) {
|
|
12
|
+
createIntegration(
|
|
13
|
+
accountId: $accountId
|
|
14
|
+
name: $name
|
|
15
|
+
key: $key
|
|
16
|
+
description: $description
|
|
17
|
+
) {
|
|
18
|
+
id
|
|
19
|
+
key
|
|
20
|
+
name
|
|
21
|
+
createdAt
|
|
22
|
+
description
|
|
23
|
+
status
|
|
24
|
+
account {
|
|
25
|
+
id
|
|
26
|
+
key
|
|
27
|
+
name
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
export default async function createIntegrationFromFile(graphqlClient, apiToken, options, config, fsImpl = fs) {
|
|
33
|
+
let integrationData;
|
|
34
|
+
try {
|
|
35
|
+
const content = fsImpl.readFileSync('integration.json', 'utf8');
|
|
36
|
+
integrationData = JSON.parse(content);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
error: `Failed to read integration.json: ${error instanceof Error ? error.message : String(error)}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const key = integrationData.__key;
|
|
45
|
+
if (typeof key !== 'string' || !key) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
error: 'integration.json must have a "__key" field',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const name = (typeof integrationData.name === 'string' && integrationData.name) ||
|
|
52
|
+
sentenceCase(key);
|
|
53
|
+
let accountId;
|
|
54
|
+
if (integrationData.account &&
|
|
55
|
+
typeof integrationData.account === 'object' &&
|
|
56
|
+
integrationData.account !== null) {
|
|
57
|
+
const fileAccountId = integrationData.account.__id;
|
|
58
|
+
if (typeof fileAccountId === 'string' && fileAccountId) {
|
|
59
|
+
const accountResult = await resolveAccountId({ account: fileAccountId }, apiToken, graphqlClient, config);
|
|
60
|
+
if (accountResult.error) {
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: `Account in integration.json not found: ${accountResult.error}`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
accountId = accountResult.accountId;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!accountId) {
|
|
70
|
+
const accountResult = await resolveAccountId(options, apiToken, graphqlClient, config);
|
|
71
|
+
if (accountResult.error) {
|
|
72
|
+
return { success: false, error: accountResult.error };
|
|
73
|
+
}
|
|
74
|
+
accountId = accountResult.accountId;
|
|
75
|
+
}
|
|
76
|
+
if (!accountId) {
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
error: 'Account is required. Use -a flag to specify account id or key, or set a default with: great config set account <id>',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const result = await graphqlClient.request(CreateIntegrationMutationDocument, {
|
|
83
|
+
accountId,
|
|
84
|
+
name,
|
|
85
|
+
key,
|
|
86
|
+
description: integrationData.description,
|
|
87
|
+
});
|
|
88
|
+
if (result.error) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: `Failed to create integration: ${result.error.message}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const integration = result.data?.createIntegration;
|
|
95
|
+
if (!integration) {
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
error: 'Failed to create integration: no data returned',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
success: true,
|
|
103
|
+
integration: {
|
|
104
|
+
id: integration.id,
|
|
105
|
+
key: integration.key,
|
|
106
|
+
name: integration.name,
|
|
107
|
+
status: integration.status,
|
|
108
|
+
account: {
|
|
109
|
+
id: integration.account.id,
|
|
110
|
+
key: integration.account.key,
|
|
111
|
+
name: integration.account.name,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=createIntegrationFromFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIntegrationFromFile.js","sourceRoot":"","sources":["../../src/utils/createIntegrationFromFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAGjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAGtD,MAAM,iCAAiC,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B5C,CAAA;AAkBD,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,yBAAyB,CACrD,aAAmC,EACnC,QAAgB,EAChB,OAA6B,EAC7B,MAA2B,EAC3B,MAAM,GAAG,EAAE;IAGX,IAAI,eAAwC,CAAA;IAC5C,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;QAC/D,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,oCAAoC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SACpG,CAAA;IACH,CAAC;IAGD,MAAM,GAAG,GAAG,eAAe,CAAC,KAAK,CAAA;IACjC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC;QACpC,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,4CAA4C;SACpD,CAAA;IACH,CAAC;IAGD,MAAM,IAAI,GACR,CA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AAS;QACT,IAAI;QACJ,GAAG;QACH,WAAW,EAAE,eAAe,CAAC,WAAiC;KAC/D,CACF,CAAA;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,iCAAiC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE;SAC/D,CAAA;IACH,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAA;IAClD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,gDAAgD;SACxD,CAAA;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,WAAW,EAAE;YACX,EAAE,EAAE,WAAW,CAAC,EAAE;YAClB,GAAG,EAAE,WAAW,CAAC,GAAG;YACpB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,MAAM,EAAE,WAAW,CAAC,MAAM;YAC1B,OAAO,EAAE;gBACP,EAAE,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE;gBAC1B,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG;gBAC5B,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI;aAC/B;SACF;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"determineNameAndKey.js","sourceRoot":"","sources":["../../src/utils/determineNameAndKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,KAAa;IAIvD,OAAO;QACL,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC;QACrB,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC;KAC1B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type GraphQLRequestClient } from './graphqlClient.js';
|
|
2
|
+
import type { Response } from '../generated/graphql.js';
|
|
3
|
+
export declare function dispatchAction(integrationId: string, type: string, payload: unknown, apiToken?: string, client?: GraphQLRequestClient, baseUrl?: string): Promise<Response>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { createGraphQLClient, } from './graphqlClient.js';
|
|
3
|
+
const DispatchMutationDocument = gql `
|
|
4
|
+
mutation Dispatch(
|
|
5
|
+
$integrationId: ID!
|
|
6
|
+
$type: String!
|
|
7
|
+
$payload: JSON!
|
|
8
|
+
$waitForResponse: Boolean
|
|
9
|
+
) {
|
|
10
|
+
dispatch(
|
|
11
|
+
integrationId: $integrationId
|
|
12
|
+
type: $type
|
|
13
|
+
payload: $payload
|
|
14
|
+
waitForResponse: $waitForResponse
|
|
15
|
+
) {
|
|
16
|
+
id
|
|
17
|
+
status
|
|
18
|
+
data
|
|
19
|
+
error
|
|
20
|
+
warning
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
export async function dispatchAction(integrationId, type, payload, apiToken, client, baseUrl) {
|
|
25
|
+
const graphqlClient = client ?? createGraphQLClient(apiToken, baseUrl);
|
|
26
|
+
const result = await graphqlClient.request(DispatchMutationDocument, {
|
|
27
|
+
integrationId,
|
|
28
|
+
type,
|
|
29
|
+
payload,
|
|
30
|
+
waitForResponse: true,
|
|
31
|
+
});
|
|
32
|
+
if (result.error) {
|
|
33
|
+
throw new Error(result.error.message);
|
|
34
|
+
}
|
|
35
|
+
return result.data?.dispatch ?? { id: 'error', status: 'error' };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/utils/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAA;AAG3B,MAAM,wBAAwB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;CAoBnC,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,aAAqB,EACrB,IAAY,EACZ,OAAgB,EAChB,QAAiB,EACjB,MAA6B,EAC7B,OAAgB;IAEhB,MAAM,aAAa,GAAG,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACtE,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CACxC,wBAAwB,EACxB;QACE,aAAa;QACb,IAAI;QACJ,OAAO;QACP,eAAe,EAAE,IAAI;KACtB,CACF,CAAA;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,EAAE,QAAQ,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;AAClE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
export function fetchIdFromFile(fsImpl = fs) {
|
|
3
|
+
try {
|
|
4
|
+
const content = fsImpl.readFileSync('integration.json', 'utf8');
|
|
5
|
+
const integration = JSON.parse(content);
|
|
6
|
+
return integration.__id;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function fetchIntegrationFromFile(fsImpl = fs) {
|
|
13
|
+
try {
|
|
14
|
+
const content = fsImpl.readFileSync('integration.json', 'utf8');
|
|
15
|
+
return JSON.parse(content);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=fetchLocal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchLocal.js","sourceRoot":"","sources":["../../src/utils/fetchLocal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AAExB,MAAM,UAAU,eAAe,CAAC,MAAM,GAAG,EAAE;IACzC,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;QAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACvC,OAAO,WAAW,CAAC,IAAI,CAAA;IACzB,CAAC;IAAC,MAAM,CAAC;QAEP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,MAAM,GAAG,EAAE;IAEX,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type GraphQLRequestClient } from './graphqlClient.js';
|
|
2
|
+
export declare const SessionQueryDocument: import("graphql/index.js").DocumentNode;
|
|
3
|
+
export interface SessionResult {
|
|
4
|
+
userName?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function fetchSession(apiToken?: string, client?: GraphQLRequestClient, baseUrl?: string): Promise<SessionResult>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { createGraphQLClient, } from './graphqlClient.js';
|
|
3
|
+
export const SessionQueryDocument = gql `
|
|
4
|
+
query Session {
|
|
5
|
+
session {
|
|
6
|
+
user {
|
|
7
|
+
id
|
|
8
|
+
name
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
export async function fetchSession(apiToken, client, baseUrl) {
|
|
14
|
+
const graphqlClient = client ?? createGraphQLClient(apiToken, baseUrl);
|
|
15
|
+
try {
|
|
16
|
+
const sessionResult = await graphqlClient.request(SessionQueryDocument, {});
|
|
17
|
+
if (sessionResult.error) {
|
|
18
|
+
const errorMessage = sessionResult.error.message || String(sessionResult.error);
|
|
19
|
+
return {
|
|
20
|
+
error: errorMessage,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
userName: sessionResult.data?.session?.user?.name,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
29
|
+
return {
|
|
30
|
+
error: `Could not fetch session: ${errorMessage}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=fetchSession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchSession.js","sourceRoot":"","sources":["../../src/utils/fetchSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AAEjC,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAA;AAE3B,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAA;;;;;;;;;CAStC,CAAA;AAOD,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAiB,EACjB,MAA6B,EAC7B,OAAgB;IAEhB,MAAM,aAAa,GAAG,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAEtE,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,OAAO,CAC/C,oBAAoB,EACpB,EAAE,CACH,CAAA;QAGD,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;YACxB,MAAM,YAAY,GAChB,aAAa,CAAC,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;YAC5D,OAAO;gBACL,KAAK,EAAE,YAAY;aACpB,CAAA;QACH,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI;SAClD,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3E,OAAO;YACL,KAAK,EAAE,4BAA4B,YAAY,EAAE;SAClD,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RequestDocument, Variables } from 'graphql-request';
|
|
2
|
+
interface RequestResult<T> {
|
|
3
|
+
data?: T;
|
|
4
|
+
error?: Error;
|
|
5
|
+
}
|
|
6
|
+
export interface GraphQLRequestClient {
|
|
7
|
+
request: <T, V extends Variables = Variables>(document: RequestDocument, variables: V) => Promise<RequestResult<T>>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createGraphQLClient(token?: string, baseUrl?: string): GraphQLRequestClient;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { GraphQLClient, ClientError } from 'graphql-request';
|
|
2
|
+
import { getApiBaseUrl } from './config.js';
|
|
3
|
+
export function createGraphQLClient(token, baseUrl) {
|
|
4
|
+
const apiUrl = baseUrl ?? getApiBaseUrl();
|
|
5
|
+
const graphQLUrl = `${apiUrl}/graphql`;
|
|
6
|
+
const client = new GraphQLClient(graphQLUrl, {
|
|
7
|
+
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
request: async (document, variables) => {
|
|
11
|
+
try {
|
|
12
|
+
const data = await client.request(document, variables);
|
|
13
|
+
return { data };
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error instanceof ClientError) {
|
|
17
|
+
return { error: error, data: error.response.data };
|
|
18
|
+
}
|
|
19
|
+
return { error: error };
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=graphqlClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphqlClient.js","sourceRoot":"","sources":["../../src/utils/graphqlClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAe3C,MAAM,UAAU,mBAAmB,CACjC,KAAc,EACd,OAAgB;IAEhB,MAAM,MAAM,GAAG,OAAO,IAAI,aAAa,EAAE,CAAA;IACzC,MAAM,UAAU,GAAG,GAAG,MAAM,UAAU,CAAA;IAEtC,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,UAAU,EAAE;QAC3C,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE;KAC3D,CAAC,CAAA;IAEF,OAAO;QACL,OAAO,EAAE,KAAK,EACZ,QAAyB,EACzB,SAAY,EACe,EAAE;YAC7B,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAI,QAAQ,EAAE,SAAS,CAAC,CAAA;gBACzD,OAAO,EAAE,IAAI,EAAE,CAAA;YACjB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;oBAEjC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAS,EAAE,CAAA;gBACzD,CAAC;gBACD,OAAO,EAAE,KAAK,EAAE,KAAc,EAAE,CAAA;YAClC,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export function isNotFoundError(error) {
|
|
3
|
+
const errorWithResponse = error;
|
|
4
|
+
if (errorWithResponse.response?.errors) {
|
|
5
|
+
return errorWithResponse.response.errors.some((err) => err.extensions?.code === 'NOT_FOUND');
|
|
6
|
+
}
|
|
7
|
+
return error?.message?.includes('NOT_FOUND');
|
|
8
|
+
}
|
|
9
|
+
export function handleGraphQLError(error, log) {
|
|
10
|
+
if (!error)
|
|
11
|
+
return;
|
|
12
|
+
const isAuthError = error.message.includes('Authentication required') ||
|
|
13
|
+
error.message.includes('Not authenticated');
|
|
14
|
+
if (isAuthError) {
|
|
15
|
+
log(chalk.red(`Not logged in. Run ${chalk.bold('great login')}.`));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
log(chalk.red(error.message));
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=graphqlError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphqlError.js","sourceRoot":"","sources":["../../src/utils/graphqlError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,MAAM,UAAU,eAAe,CAAC,KAAY;IAE1C,MAAM,iBAAiB,GAAG,KAIzB,CAAA;IAED,IAAI,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;QACvC,OAAO,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAC3C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,KAAK,WAAW,CAC9C,CAAA;IACH,CAAC;IAGD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAA;AAC9C,CAAC;AAKD,MAAM,UAAU,kBAAkB,CAChC,KAAwB,EACxB,GAA8B;IAE9B,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,MAAM,WAAW,GACf,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAC;QACjD,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAA;IAC7C,IAAI,WAAW,EAAE,CAAC;QAChB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;QAClE,OAAM;IACR,CAAC;IAGD,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function hashContent(data: Record<string, unknown>): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
export default function hashContent(data) {
|
|
3
|
+
const { __id, __key, __timestamp, name, description, value, ...content } = data;
|
|
4
|
+
const jsonString = JSON.stringify(content);
|
|
5
|
+
return crypto.createHash('sha256').update(jsonString).digest('hex');
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=hashContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashContent.js","sourceRoot":"","sources":["../../src/utils/hashContent.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAYhC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAA6B;IAK/D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GACtE,IAAI,CAAA;IAGN,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAG1C,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function decodeJwt(token) {
|
|
2
|
+
try {
|
|
3
|
+
const parts = token.split('.');
|
|
4
|
+
if (parts.length !== 3) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
const payload = parts[1];
|
|
8
|
+
const base64 = payload.replace(/-/g, '+').replace(/_/g, '/');
|
|
9
|
+
const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), '=');
|
|
10
|
+
const jsonString = Buffer.from(padded, 'base64').toString('utf8');
|
|
11
|
+
return JSON.parse(jsonString);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function getJwtExpiration(token) {
|
|
18
|
+
const payload = decodeJwt(token);
|
|
19
|
+
if (!payload || !payload.exp) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return payload.exp * 1000;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=jwt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../../src/utils/jwt.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,CAAC;QAEH,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAA;QACb,CAAC;QAGD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QAExB,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC1B,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAC/C,GAAG,CACJ,CAAA;QAGD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACjE,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAe,CAAA;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;IAChC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QAC7B,OAAO,SAAS,CAAA;IAClB,CAAC;IAGD,OAAO,OAAO,CAAC,GAAG,GAAG,IAAI,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface LocalElement {
|
|
2
|
+
folder: string;
|
|
3
|
+
key: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
remoteId?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function promptForValueSetting(elements: LocalElement[], log: (message: string) => void): Promise<boolean>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
export async function promptForValueSetting(elements, log) {
|
|
4
|
+
const valueElementsWithValue = elements.filter((element) => element.folder === 'values' && element.data.value !== undefined);
|
|
5
|
+
if (valueElementsWithValue.length === 0) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
log(chalk.white('The following value elements have values set:'));
|
|
9
|
+
for (const element of valueElementsWithValue) {
|
|
10
|
+
log(chalk.white(` - ${element.key}`));
|
|
11
|
+
}
|
|
12
|
+
log('');
|
|
13
|
+
try {
|
|
14
|
+
const shouldSet = await confirm({
|
|
15
|
+
message: 'Set these values in Integreat and remove from files?',
|
|
16
|
+
default: true,
|
|
17
|
+
});
|
|
18
|
+
return shouldSet;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new Error('User cancelled');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=promptForValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promptForValue.js","sourceRoot":"","sources":["../../src/utils/promptForValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAA;AAczB,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,QAAwB,EACxB,GAA8B;IAG9B,MAAM,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAC5C,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAClE,CAAA;IAGD,IAAI,sBAAsB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO,KAAK,CAAA;IACd,CAAC;IAGD,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC,CAAA;IACjE,KAAK,MAAM,OAAO,IAAI,sBAAsB,EAAE,CAAC;QAC7C,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IACxC,CAAC;IACD,GAAG,CAAC,EAAE,CAAC,CAAA;IAGP,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC;YAC9B,OAAO,EAAE,sDAAsD;YAC/D,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QACF,OAAO,SAAS,CAAA;IAClB,CAAC;IAAC,MAAM,CAAC;QAEP,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IACnC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Conf from 'conf';
|
|
2
|
+
import { type ConfigSchema } from './config.js';
|
|
3
|
+
import { type GraphQLRequestClient } from './graphqlClient.js';
|
|
4
|
+
export interface AccountResult {
|
|
5
|
+
account?: {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
key: string;
|
|
9
|
+
};
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ResolveAccountResult {
|
|
13
|
+
accountId?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
source?: 'flag' | 'config';
|
|
16
|
+
}
|
|
17
|
+
export declare function resolveAccountId(options: {
|
|
18
|
+
account?: string;
|
|
19
|
+
}, apiToken: string, client: GraphQLRequestClient, config?: Conf<ConfigSchema>): Promise<ResolveAccountResult>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { getConfigValue } from './config.js';
|
|
3
|
+
import { createGraphQLClient, } from './graphqlClient.js';
|
|
4
|
+
import { isNotFoundError } from './graphqlError.js';
|
|
5
|
+
const AccountByIdQueryDocument = gql `
|
|
6
|
+
query AccountById($id: ID!) {
|
|
7
|
+
account(id: $id) {
|
|
8
|
+
id
|
|
9
|
+
name
|
|
10
|
+
key
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
const AccountByKeyQueryDocument = gql `
|
|
15
|
+
query AccountByKey($key: ID!) {
|
|
16
|
+
accountByKey(key: $key) {
|
|
17
|
+
id
|
|
18
|
+
name
|
|
19
|
+
key
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
async function fetchAccount(accountId, apiToken, client, baseUrl) {
|
|
24
|
+
const graphqlClient = client ?? createGraphQLClient(apiToken, baseUrl);
|
|
25
|
+
try {
|
|
26
|
+
const idResult = await graphqlClient.request(AccountByIdQueryDocument, { id: accountId });
|
|
27
|
+
if (idResult.error && !isNotFoundError(idResult.error)) {
|
|
28
|
+
return {
|
|
29
|
+
error: `Could not fetch account: ${idResult.error.message}`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (idResult.data?.account) {
|
|
33
|
+
return { account: idResult.data.account };
|
|
34
|
+
}
|
|
35
|
+
const keyResult = await graphqlClient.request(AccountByKeyQueryDocument, { key: accountId });
|
|
36
|
+
if (keyResult.error && !isNotFoundError(keyResult.error)) {
|
|
37
|
+
return {
|
|
38
|
+
error: `Could not fetch account: ${keyResult.error.message}`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (keyResult.data?.accountByKey) {
|
|
42
|
+
return { account: keyResult.data.accountByKey };
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
error: `Account "${accountId}" not found`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
50
|
+
return {
|
|
51
|
+
error: `Could not fetch account: ${errorMessage}`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export async function resolveAccountId(options, apiToken, client, config) {
|
|
56
|
+
if (options?.account) {
|
|
57
|
+
const result = await fetchAccount(options.account, apiToken, client);
|
|
58
|
+
if (result.error) {
|
|
59
|
+
return { error: result.error };
|
|
60
|
+
}
|
|
61
|
+
return { accountId: result.account?.id, source: 'flag' };
|
|
62
|
+
}
|
|
63
|
+
const defaultAccount = getConfigValue('account', config);
|
|
64
|
+
if (defaultAccount) {
|
|
65
|
+
const result = await fetchAccount(defaultAccount, apiToken, client);
|
|
66
|
+
if (result.error) {
|
|
67
|
+
return {
|
|
68
|
+
error: `Default account '${defaultAccount}' not found. Update with: great config set account <id>, or unset with: great config unset account`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return { accountId: result.account?.id, source: 'config' };
|
|
72
|
+
}
|
|
73
|
+
return { accountId: undefined };
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=resolveAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveAccount.js","sourceRoot":"","sources":["../../src/utils/resolveAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAA;AAC/D,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAMnD,MAAM,wBAAwB,GAAG,GAAG,CAAA;;;;;;;;CAQnC,CAAA;AAED,MAAM,yBAAyB,GAAG,GAAG,CAAA;;;;;;;;CAQpC,CAAA;AAWD,KAAK,UAAU,YAAY,CACzB,SAAiB,EACjB,QAAiB,EACjB,MAA6B,EAC7B,OAAgB;IAEhB,MAAM,aAAa,GAAG,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAEtE,IAAI,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,OAAO,CAC1C,wBAAwB,EACxB,EAAE,EAAE,EAAE,SAAS,EAAE,CAClB,CAAA;QAGD,IAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO;gBACL,KAAK,EAAE,4BAA4B,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE;aAC5D,CAAA;QACH,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC;YAC3B,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAA;QAC3C,CAAC;QAGD,MAAM,SAAS,GAAG,MAAM,aAAa,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AA;IACxD,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;QACnE,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO;gBACL,KAAK,EAAE,oBAAoB,cAAc,oGAAoG;aAC9I,CAAA;QACH,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;IAC5D,CAAC;IAGD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ElementType } from '../generated/graphql.js';
|
|
2
|
+
import type { GraphQLRequestClient } from './graphqlClient.js';
|
|
3
|
+
export interface ResolveElementOptions {
|
|
4
|
+
identifier: string;
|
|
5
|
+
type: ElementType;
|
|
6
|
+
integrationIdentifier?: string;
|
|
7
|
+
accountId?: string;
|
|
8
|
+
apiToken: string;
|
|
9
|
+
client: GraphQLRequestClient;
|
|
10
|
+
log: (message: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveElement(options: ResolveElementOptions): Promise<{
|
|
13
|
+
id: string;
|
|
14
|
+
key: string;
|
|
15
|
+
__typename: string;
|
|
16
|
+
content?: {
|
|
17
|
+
data?: unknown | null;
|
|
18
|
+
} | null;
|
|
19
|
+
value?: unknown | null;
|
|
20
|
+
} | undefined>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { gql } from 'graphql-tag';
|
|
3
|
+
import { handleGraphQLError, isNotFoundError } from './graphqlError.js';
|
|
4
|
+
import { resolveIntegration } from './resolveIntegration.js';
|
|
5
|
+
const ElementByIdQueryDocument = gql `
|
|
6
|
+
query ElementById($id: ID!) {
|
|
7
|
+
element(id: $id) {
|
|
8
|
+
id
|
|
9
|
+
key
|
|
10
|
+
__typename
|
|
11
|
+
content {
|
|
12
|
+
data
|
|
13
|
+
}
|
|
14
|
+
... on Value {
|
|
15
|
+
value
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
const ElementByKeyQueryDocument = gql `
|
|
21
|
+
query ElementByKey($integrationId: ID!, $key: ID!, $type: ElementType!) {
|
|
22
|
+
elementByKey(integrationId: $integrationId, key: $key, type: $type) {
|
|
23
|
+
id
|
|
24
|
+
key
|
|
25
|
+
__typename
|
|
26
|
+
content {
|
|
27
|
+
data
|
|
28
|
+
}
|
|
29
|
+
... on Value {
|
|
30
|
+
value
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
export async function resolveElement(options) {
|
|
36
|
+
const { identifier, type, integrationIdentifier, accountId, apiToken, client, log, } = options;
|
|
37
|
+
const idResult = await client.request(ElementByIdQueryDocument, { id: identifier });
|
|
38
|
+
if (idResult.error && !isNotFoundError(idResult.error)) {
|
|
39
|
+
handleGraphQLError(idResult.error, log);
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
if (idResult.data?.element) {
|
|
43
|
+
return idResult.data.element;
|
|
44
|
+
}
|
|
45
|
+
if (!integrationIdentifier) {
|
|
46
|
+
log(chalk.red(`Element "${identifier}" not found. To look up by key, provide an integration with -i flag or run from an integration directory.`));
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const integrationResult = await resolveIntegration(integrationIdentifier, accountId, apiToken, client);
|
|
50
|
+
if (integrationResult.error || !integrationResult.id) {
|
|
51
|
+
log(chalk.red(integrationResult.error || 'Integration not found'));
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const integrationId = integrationResult.id;
|
|
55
|
+
const keyResult = await client.request(ElementByKeyQueryDocument, { integrationId, key: identifier, type });
|
|
56
|
+
if (keyResult.error && !isNotFoundError(keyResult.error)) {
|
|
57
|
+
handleGraphQLError(keyResult.error, log);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (!keyResult.data?.elementByKey) {
|
|
61
|
+
const integrationName = integrationResult.name || integrationResult.id;
|
|
62
|
+
log(chalk.red(`Element with key "${identifier}" not found in integration "${integrationName}"`));
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return keyResult.data.elementByKey;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=resolveElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveElement.js","sourceRoot":"","sources":["../../src/utils/resolveElement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAQ5D,MAAM,wBAAwB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;CAcnC,CAAA;AAED,MAAM,yBAAyB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;CAcpC,CAAA;AAoBD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B;IAUjE,MAAM,EACJ,UAAU,EACV,IAAI,EACJ,qBAAqB,EACrB,SAAS,EACT,QAAQ,EACR,MAAM,EACN,GAAG,GACJ,GAAG,OAAO,CAAA;IAGX,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CACnC,wBAAwB,EACxB,EAAE,EAAE,EAAE,UAAU,EAAE,CACnB,CAAA;IAED,IAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACvD,kBAAkB,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QACvC,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,QAAQ,CA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Y,CAAA;AACpC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type GraphQLRequestClient } from './graphqlClient.js';
|
|
2
|
+
export declare const IntegrationQueryDocument: import("graphql/index.js").DocumentNode;
|
|
3
|
+
export declare const IntegrationByKeyQueryDocument: import("graphql/index.js").DocumentNode;
|
|
4
|
+
export interface IntegrationResult {
|
|
5
|
+
id: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function resolveIntegration(identifier: string, accountId: string | undefined, apiToken?: string, client?: GraphQLRequestClient, baseUrl?: string): Promise<IntegrationResult>;
|