@wirechunk/cli 0.0.1-rc.3 → 0.0.2
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/build/main.js +4157 -454
- package/package.json +6 -1
- package/src/commands/bootstrap.ts +1 -1
- package/src/commands/create-extension-version.ts +48 -102
- package/src/commands/create-user.ts +9 -6
- package/src/commands/edit-admin.ts +77 -15
- package/src/commands/ext-dev/{db-connect-info.ts → get-db-url.ts} +3 -3
- package/src/commands/ext-dev/init-db.ts +3 -2
- package/src/core-api/api.ts +4216 -0
- package/src/core-api/mutations/create-extension-version.generated.ts +96 -0
- package/src/core-api/mutations/create-extension-version.graphql +14 -0
- package/src/core-api/operations.ts +23 -0
- package/src/main.ts +13 -6
- package/src/users/permissions.ts +15 -12
- package/tsconfig.json +4 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import type * as Types from '#api';
|
|
3
|
+
|
|
4
|
+
export type CreateExtensionVersionMutationVariables = Types.Exact<{
|
|
5
|
+
input: Types.CreateExtensionVersionInput;
|
|
6
|
+
}>;
|
|
7
|
+
|
|
8
|
+
export type CreateExtensionVersionMutation = {
|
|
9
|
+
createExtensionVersion:
|
|
10
|
+
| { __typename: 'AuthorizationError'; message: string }
|
|
11
|
+
| {
|
|
12
|
+
__typename: 'CreateExtensionVersionSuccessResult';
|
|
13
|
+
signedUrl: string;
|
|
14
|
+
extensionVersion: { __typename: 'ExtensionVersion'; id: string };
|
|
15
|
+
}
|
|
16
|
+
| { __typename: 'GenericInternalError'; message: string }
|
|
17
|
+
| { __typename: 'GenericUserError'; message: string };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const CreateExtensionVersionDocument = {
|
|
21
|
+
kind: 'Document',
|
|
22
|
+
definitions: [
|
|
23
|
+
{
|
|
24
|
+
kind: 'OperationDefinition',
|
|
25
|
+
operation: 'mutation',
|
|
26
|
+
name: { kind: 'Name', value: 'CreateExtensionVersion' },
|
|
27
|
+
variableDefinitions: [
|
|
28
|
+
{
|
|
29
|
+
kind: 'VariableDefinition',
|
|
30
|
+
variable: { kind: 'Variable', name: { kind: 'Name', value: 'input' } },
|
|
31
|
+
type: {
|
|
32
|
+
kind: 'NonNullType',
|
|
33
|
+
type: {
|
|
34
|
+
kind: 'NamedType',
|
|
35
|
+
name: { kind: 'Name', value: 'CreateExtensionVersionInput' },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
selectionSet: {
|
|
41
|
+
kind: 'SelectionSet',
|
|
42
|
+
selections: [
|
|
43
|
+
{
|
|
44
|
+
kind: 'Field',
|
|
45
|
+
name: { kind: 'Name', value: 'createExtensionVersion' },
|
|
46
|
+
arguments: [
|
|
47
|
+
{
|
|
48
|
+
kind: 'Argument',
|
|
49
|
+
name: { kind: 'Name', value: 'input' },
|
|
50
|
+
value: { kind: 'Variable', name: { kind: 'Name', value: 'input' } },
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
selectionSet: {
|
|
54
|
+
kind: 'SelectionSet',
|
|
55
|
+
selections: [
|
|
56
|
+
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
|
|
57
|
+
{
|
|
58
|
+
kind: 'InlineFragment',
|
|
59
|
+
typeCondition: {
|
|
60
|
+
kind: 'NamedType',
|
|
61
|
+
name: { kind: 'Name', value: 'CreateExtensionVersionSuccessResult' },
|
|
62
|
+
},
|
|
63
|
+
selectionSet: {
|
|
64
|
+
kind: 'SelectionSet',
|
|
65
|
+
selections: [
|
|
66
|
+
{
|
|
67
|
+
kind: 'Field',
|
|
68
|
+
name: { kind: 'Name', value: 'extensionVersion' },
|
|
69
|
+
selectionSet: {
|
|
70
|
+
kind: 'SelectionSet',
|
|
71
|
+
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'id' } }],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{ kind: 'Field', name: { kind: 'Name', value: 'signedUrl' } },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
kind: 'InlineFragment',
|
|
80
|
+
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Error' } },
|
|
81
|
+
selectionSet: {
|
|
82
|
+
kind: 'SelectionSet',
|
|
83
|
+
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'message' } }],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
} as unknown as DocumentNode<
|
|
94
|
+
CreateExtensionVersionMutation,
|
|
95
|
+
CreateExtensionVersionMutationVariables
|
|
96
|
+
>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
mutation CreateExtensionVersion($input: CreateExtensionVersionInput!) {
|
|
2
|
+
createExtensionVersion(input: $input) {
|
|
3
|
+
__typename
|
|
4
|
+
... on CreateExtensionVersionSuccessResult {
|
|
5
|
+
extensionVersion {
|
|
6
|
+
id
|
|
7
|
+
}
|
|
8
|
+
signedUrl
|
|
9
|
+
}
|
|
10
|
+
... on Error {
|
|
11
|
+
message
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GraphQLClient } from 'graphql-request';
|
|
2
|
+
import type {
|
|
3
|
+
CreateExtensionVersionMutation,
|
|
4
|
+
CreateExtensionVersionMutationVariables,
|
|
5
|
+
} from './mutations/create-extension-version.generated.ts';
|
|
6
|
+
import { CreateExtensionVersionDocument } from './mutations/create-extension-version.generated.ts';
|
|
7
|
+
|
|
8
|
+
export const createExtensionVersion = ({
|
|
9
|
+
client,
|
|
10
|
+
variables,
|
|
11
|
+
sessionAuthToken,
|
|
12
|
+
}: {
|
|
13
|
+
client: GraphQLClient;
|
|
14
|
+
variables: CreateExtensionVersionMutationVariables;
|
|
15
|
+
sessionAuthToken: string;
|
|
16
|
+
}): Promise<CreateExtensionVersionMutation> =>
|
|
17
|
+
client.request({
|
|
18
|
+
document: CreateExtensionVersionDocument,
|
|
19
|
+
variables,
|
|
20
|
+
requestHeaders: {
|
|
21
|
+
Authorization: `Bearer ${sessionAuthToken}`,
|
|
22
|
+
},
|
|
23
|
+
});
|
package/src/main.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { bootstrap } from './commands/bootstrap.ts';
|
|
|
7
7
|
import { createExtensionVersion } from './commands/create-extension-version.ts';
|
|
8
8
|
import { createUser } from './commands/create-user.ts';
|
|
9
9
|
import { editAdmin } from './commands/edit-admin.ts';
|
|
10
|
-
import {
|
|
10
|
+
import { getDbUrl } from './commands/ext-dev/get-db-url.ts';
|
|
11
11
|
import { initDb } from './commands/ext-dev/init-db.ts';
|
|
12
12
|
import type { Env } from './env.ts';
|
|
13
13
|
import { parseEnv } from './env.ts';
|
|
@@ -18,7 +18,7 @@ const program = new Command()
|
|
|
18
18
|
.option('--verbose', 'output debug logging')
|
|
19
19
|
.option(
|
|
20
20
|
'--env-mode <mode>',
|
|
21
|
-
'the mode to use for finding .env files to load environment variables, such as "test" to load .env, .env.test, .env.local, and .env.test.local',
|
|
21
|
+
'the mode to use for finding .env files to load environment variables, such as "test" to load .env, .env.test, .env.local, and .env.test.local; also for finding config files to include when creating an extension or extension version, such as config.production.json',
|
|
22
22
|
).description(`The official Wirechunk CLI
|
|
23
23
|
|
|
24
24
|
By default, environment variables are loaded from the .env file in the current working directory,
|
|
@@ -65,6 +65,10 @@ program
|
|
|
65
65
|
'the ID of the extension, can be set with an EXTENSION_ID environment variable instead',
|
|
66
66
|
)
|
|
67
67
|
.requiredOption('--version-name <string>', 'the name of the version')
|
|
68
|
+
.option(
|
|
69
|
+
'--config-file <string>',
|
|
70
|
+
'the path to a file to use when creating the extension version, containing environment-style key-value pairs',
|
|
71
|
+
)
|
|
68
72
|
.action(withOptionsAndEnv(createExtensionVersion));
|
|
69
73
|
|
|
70
74
|
program
|
|
@@ -94,15 +98,15 @@ program
|
|
|
94
98
|
const extDev = program.command('ext-dev').description('extension development commands');
|
|
95
99
|
|
|
96
100
|
extDev
|
|
97
|
-
.command('db-
|
|
101
|
+
.command('get-db-url')
|
|
98
102
|
.description(
|
|
99
|
-
'write the connection info for the extension database to a .local
|
|
103
|
+
'write the connection info for the extension database to a .env.local or .env.<env-mode>.local file',
|
|
100
104
|
)
|
|
101
105
|
.option(
|
|
102
106
|
'--extension-id <string>',
|
|
103
107
|
'the ID of the extension, can be set with an EXTENSION_ID environment variable instead',
|
|
104
108
|
)
|
|
105
|
-
.action(withOptionsAndEnv(
|
|
109
|
+
.action(withOptionsAndEnv(getDbUrl));
|
|
106
110
|
|
|
107
111
|
extDev
|
|
108
112
|
.command('init-db')
|
|
@@ -118,10 +122,13 @@ extDev
|
|
|
118
122
|
|
|
119
123
|
program
|
|
120
124
|
.command('edit-admin')
|
|
121
|
-
.description('edit a platform admin user')
|
|
125
|
+
.description('edit a platform admin user or make a user a platform admin')
|
|
122
126
|
.requiredOption('--platform-id <string>', 'the ID of the platform to edit')
|
|
123
127
|
.requiredOption('--user-id <string>', 'the ID of the admin user to edit')
|
|
124
128
|
.option('--owner', 'grants the user full permission to manage everything on the platform')
|
|
129
|
+
.option('--no-owner', 'removes owner privileges on the platform')
|
|
130
|
+
.option('--active', 'activates or deactivates the user’s admin access on the platform')
|
|
131
|
+
.option('--no-active', 'deactivates the user’s admin access on the platform')
|
|
125
132
|
.option('--revoke-all-permissions', 'revokes all permission of the user on their platform')
|
|
126
133
|
.action(withOptionsAndEnv(editAdmin));
|
|
127
134
|
|
package/src/users/permissions.ts
CHANGED
|
@@ -1,39 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cleanSmallId } from '@wirechunk/lib/clean-small-id.ts';
|
|
2
|
+
import { PermissionName } from '@wirechunk/lib/graphql-api-enums.ts';
|
|
2
3
|
import type { CommonQueryMethods } from 'slonik';
|
|
3
4
|
import { sql } from 'slonik';
|
|
4
5
|
import { voidSelectSchema } from '../util.ts';
|
|
5
6
|
|
|
6
|
-
export const allPermissions = Object.values(
|
|
7
|
+
export const allPermissions = Object.values(PermissionName);
|
|
7
8
|
|
|
8
9
|
export const revokeAllUserPlatformPermissions = async (
|
|
9
10
|
{
|
|
10
|
-
|
|
11
|
+
platformAdminId,
|
|
11
12
|
}: {
|
|
12
|
-
|
|
13
|
+
platformAdminId: string;
|
|
13
14
|
},
|
|
14
15
|
db: CommonQueryMethods,
|
|
15
16
|
): Promise<void> => {
|
|
16
17
|
await db.query(
|
|
17
|
-
sql.type(
|
|
18
|
+
sql.type(
|
|
19
|
+
voidSelectSchema,
|
|
20
|
+
)`delete from "PlatformAdminPermissions" where "id" = ${platformAdminId}`,
|
|
18
21
|
);
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export const grantAllUserPlatformPermissions = async (
|
|
22
25
|
{
|
|
23
|
-
|
|
24
|
-
platformId,
|
|
26
|
+
platformAdminId,
|
|
25
27
|
}: {
|
|
26
|
-
|
|
27
|
-
platformId: string;
|
|
28
|
+
platformAdminId: string;
|
|
28
29
|
},
|
|
29
30
|
db: CommonQueryMethods,
|
|
30
31
|
): Promise<void> => {
|
|
31
32
|
await db.query(
|
|
32
33
|
sql.type(
|
|
33
34
|
voidSelectSchema,
|
|
34
|
-
)`insert into "
|
|
35
|
-
allPermissions.map(
|
|
35
|
+
)`insert into "PlatformAdminPermissions" ("id", "platformAdminId", "permission") values ${sql.join(
|
|
36
|
+
allPermissions.map(
|
|
37
|
+
(permission) => sql.fragment`(${cleanSmallId()}, ${platformAdminId}, ${permission})`,
|
|
38
|
+
),
|
|
36
39
|
sql.fragment`,`,
|
|
37
|
-
)} on conflict
|
|
40
|
+
)} on conflict ("platformAdminId", "permission") do nothing`,
|
|
38
41
|
);
|
|
39
42
|
};
|