@sprucelabs/spruce-cli 14.29.5 → 14.29.9
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/CHANGELOG.md +32 -0
- package/build/GlobalEmitter.js +2 -2
- package/build/__tests__/behavioral/InstallingASkillAtAnOrg.test.d.ts +1 -1
- package/build/__tests__/behavioral/InstallingASkillAtAnOrg.test.js +93 -93
- package/build/__tests__/behavioral/InstallingASkillAtAnOrg.test.js.map +1 -1
- package/build/__tests__/behavioral/SettingUpSchemasForModuleDistribution.test.js +2 -2
- package/build/__tests__/behavioral/events/CreatingAnEvent.test.js +2 -2
- package/build/__tests__/behavioral/events/KeepingEventsInSync2.test.js +2 -2
- package/build/__tests__/behavioral/views/CreatingASkillView.test.d.ts +1 -0
- package/build/__tests__/behavioral/views/CreatingASkillView.test.js +35 -3
- package/build/__tests__/behavioral/views/CreatingASkillView.test.js.map +1 -1
- package/build/__tests__/implementation/EventContractCleanerUtil.test.js +2 -2
- package/build/__tests__/implementation/EventTemplateItemBuilder.test.js +2 -2
- package/build/__tests__/implementation/PkgService.test.js +3 -6
- package/build/__tests__/implementation/PkgService.test.js.map +1 -1
- package/build/__tests__/implementation/SchemaStore.test.js +2 -2
- package/build/__tests__/implementation/SchemaTemplateItemBuilder.test.js +2 -2
- package/build/cli.js +11 -9
- package/build/cli.js.map +1 -1
- package/build/components/AbstractComponent.js +2 -2
- package/build/components/FormComponent.js +2 -2
- package/build/components/QuizComponent.js +2 -2
- package/build/features/AbstractAction.js +2 -2
- package/build/features/AbstractFeature.js +2 -2
- package/build/features/ActionExecuter.js +2 -2
- package/build/features/ActionFactory.js +2 -2
- package/build/features/ActionQuestionAsker.js +2 -2
- package/build/features/FeatureCommandAttacher.js +2 -2
- package/build/features/FeatureInstaller.js +2 -2
- package/build/features/OverrideActionDecorator.js +2 -2
- package/build/features/deploy/actions/HerokuAction.js.map +1 -1
- package/build/features/error/actions/CreateAction.js +2 -2
- package/build/features/error/actions/SyncAction.js +2 -2
- package/build/features/error/writers/ErrorWriter.js +2 -2
- package/build/features/event/EventFeature.js.map +1 -1
- package/build/features/event/actions/CreateAction.js +2 -2
- package/build/features/event/actions/ListenAction.js +2 -2
- package/build/features/event/builders/EventContractBuilder.js +2 -2
- package/build/features/event/builders/ListenerTemplateItemBuilder.js +2 -2
- package/build/features/event/stores/EventStore.js +2 -2
- package/build/features/event/stores/ListenerStore.js +2 -2
- package/build/features/event/writers/EventWriter.js +2 -2
- package/build/features/eventContract/EventContractFeature.js +3 -1
- package/build/features/eventContract/EventContractFeature.js.map +1 -1
- package/build/features/node/NodeFeature.js +12 -10
- package/build/features/node/NodeFeature.js.map +1 -1
- package/build/features/node/actions/UpgradeAction.js +10 -9
- package/build/features/node/actions/UpgradeAction.js.map +1 -1
- package/build/features/node/writers/NodeWriter.js +2 -2
- package/build/features/organization/OrganizationFeature.js +3 -1
- package/build/features/organization/OrganizationFeature.js.map +1 -1
- package/build/features/person/PersonFeature.js +3 -1
- package/build/features/person/PersonFeature.js.map +1 -1
- package/build/features/person/actions/LoginAction.js +2 -2
- package/build/features/sandbox/SandboxFeature.js +3 -1
- package/build/features/sandbox/SandboxFeature.js.map +1 -1
- package/build/features/schema/actions/CreateAction.js +2 -2
- package/build/features/schema/stores/SchemaStore.js +2 -2
- package/build/features/schema/utilities/schemaDisk.utility.js +2 -2
- package/build/features/schema/writers/SchemaWriter.js +2 -2
- package/build/features/skill/SkillFeature.js +2 -2
- package/build/features/skill/actions/CreateAction.js +2 -2
- package/build/features/skill/stores/SkillStore.js +2 -2
- package/build/features/skill/writers/SkillWriter.js +2 -2
- package/build/features/store/actions/CreateAction.js +2 -2
- package/build/features/test/TestFeature.js +2 -2
- package/build/features/test/TestReporter.js +2 -2
- package/build/features/test/TestRunner.js +2 -2
- package/build/features/test/actions/CreateAction.js +2 -2
- package/build/features/validateAndNormalize.utility.js +2 -2
- package/build/features/view/actions/CreateAction.js +2 -2
- package/build/features/view/writers/ViewWriter.js +2 -2
- package/build/features/vscode/VsCodeFeature.js +3 -1
- package/build/features/vscode/VsCodeFeature.js.map +1 -1
- package/build/interfaces/TerminalInterface.js +2 -2
- package/build/schemas/v2020_07_22/createConversationTopicOptions.builder.js +2 -2
- package/build/schemas/v2020_07_22/createErrorOptions.builder.js +2 -2
- package/build/schemas/v2020_07_22/createOrganizationOptions.builder.js +2 -2
- package/build/schemas/v2020_07_22/createSchemaOptions.builder.js +2 -2
- package/build/schemas/v2020_07_22/listenEventOptions.builder.js +2 -2
- package/build/schemas/v2020_07_22/syncErrorOptions.builder.js +2 -2
- package/build/schemas/v2020_07_22/syncSchemasOptions.builder.js +2 -2
- package/build/services/CommandService.js +2 -2
- package/build/services/PkgService.d.ts +4 -16
- package/build/services/PkgService.js +11 -127
- package/build/services/PkgService.js.map +1 -1
- package/build/services/ServiceFactory.d.ts +1 -2
- package/build/services/ServiceFactory.js +2 -4
- package/build/services/ServiceFactory.js.map +1 -1
- package/build/services/TypeCheckerService.js +4 -3
- package/build/services/TypeCheckerService.js.map +1 -1
- package/build/stores/AbstractLocalStore.js +2 -2
- package/build/templateItemBuilders/EventTemplateItemBuilder.js +2 -2
- package/build/templateItemBuilders/SchemaTemplateItemBuilder.js +2 -2
- package/build/tests/AbstractCliTest.js +2 -2
- package/build/tests/AbstractEventTest.js +2 -2
- package/build/tests/AbstractSchemaTest.js +2 -2
- package/build/tests/JestJsonParser.js +2 -2
- package/build/tests/fixtures/FeatureFixture.js +2 -2
- package/build/tests/fixtures/OrganizationFixture.js +2 -2
- package/build/tests/fixtures/PersonFixture.js +2 -2
- package/build/tests/fixtures/SkillFixture.js +2 -2
- package/build/types/cli.types.d.ts +1 -6
- package/build/types/cli.types.js +8 -0
- package/build/types/cli.types.js.map +1 -1
- package/build/updaters/ScriptUpdater.js +2 -2
- package/build/utilities/commander.utility.js +2 -2
- package/build/utilities/eventContractCleaner.utility.js +2 -2
- package/build/widgets/WidgetFactory.js +2 -2
- package/build/widgets/terminalKit/TKButtonWidget.js +2 -2
- package/build/widgets/terminalKit/TkBaseWidget.js +2 -2
- package/build/widgets/terminalKit/TkInputWidget.js +2 -2
- package/build/widgets/terminalKit/TkLayoutCellWidget.js +2 -2
- package/build/widgets/terminalKit/TkLayoutWidget.js +2 -2
- package/build/widgets/terminalKit/TkMenuBarWidget.js +2 -2
- package/build/widgets/terminalKit/TkPopupWidget.js +2 -2
- package/build/widgets/terminalKit/TkProgressBarWidget.js +2 -2
- package/build/widgets/terminalKit/TkTextWidget.js +2 -2
- package/build/widgets/terminalKit/termKit.utility.js +2 -2
- package/build/writers/AbstractWriter.js +2 -2
- package/build/writers/WriterFactory.js +2 -2
- package/package.json +38 -38
- package/src/__tests__/behavioral/InstallingASkillAtAnOrg.test.ts +6 -6
- package/src/__tests__/behavioral/views/CreatingASkillView.test.ts +16 -0
- package/src/__tests__/implementation/PkgService.test.ts +1 -2
- package/src/cli.ts +4 -1
- package/src/features/deploy/actions/HerokuAction.ts +1 -2
- package/src/features/event/EventFeature.ts +0 -1
- package/src/features/node/NodeFeature.ts +3 -0
- package/src/features/node/actions/UpgradeAction.ts +1 -0
- package/src/services/PkgService.ts +13 -93
- package/src/services/ServiceFactory.ts +10 -7
- package/src/types/cli.types.ts +1 -6
- package/build/__tests__/implementation/AuthService.test.d.ts +0 -14
- package/build/__tests__/implementation/AuthService.test.js +0 -255
- package/build/__tests__/implementation/AuthService.test.js.map +0 -1
- package/build/services/AuthService.d.ts +0 -23
- package/build/services/AuthService.js +0 -109
- package/build/services/AuthService.js.map +0 -1
- package/src/__tests__/implementation/AuthService.test.ts +0 -95
- package/src/services/AuthService.ts +0 -91
|
@@ -62,6 +62,9 @@ export default class NodeFeature<
|
|
|
62
62
|
|
|
63
63
|
private async handleUpgrade(): Promise<FeatureActionResponse> {
|
|
64
64
|
try {
|
|
65
|
+
this.ui.clear()
|
|
66
|
+
this.ui.renderHero('Upgrade')
|
|
67
|
+
|
|
65
68
|
this.ui.startLoading('Cleaning build...')
|
|
66
69
|
await this.Service('command').execute('yarn clean.build')
|
|
67
70
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import pathUtil from 'path'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { NpmPackage } from '../types/cli.types'
|
|
2
|
+
import {
|
|
3
|
+
diskUtil,
|
|
4
|
+
PkgService as BasePkgService,
|
|
5
|
+
} from '@sprucelabs/spruce-skill-utils'
|
|
7
6
|
import isCi from '../utilities/isCi'
|
|
8
7
|
import CommandService from './CommandService'
|
|
9
8
|
|
|
@@ -13,68 +12,12 @@ export interface AddOptions {
|
|
|
13
12
|
shouldCleanupLockFiles?: boolean
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
export default class PkgService extends
|
|
17
|
-
private
|
|
15
|
+
export default class PkgService extends BasePkgService {
|
|
16
|
+
private commandService: CommandService
|
|
18
17
|
|
|
19
|
-
public
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public set(options: {
|
|
25
|
-
path: string | string[]
|
|
26
|
-
value: string | Record<string, any> | undefined
|
|
27
|
-
}) {
|
|
28
|
-
const { path, value } = options
|
|
29
|
-
const contents = this.readPackage()
|
|
30
|
-
const updated = set(contents, path, value)
|
|
31
|
-
const destination = this.buildPath()
|
|
32
|
-
|
|
33
|
-
fs.outputFileSync(destination, JSON.stringify(updated, null, 2))
|
|
34
|
-
this._parsedPkg = undefined
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public doesExist() {
|
|
38
|
-
return diskUtil.doesFileExist(this.buildPath())
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public unset(path: string | string[]) {
|
|
42
|
-
this.set({ path, value: undefined })
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public readPackage(): Record<string, any | undefined> {
|
|
46
|
-
if (this._parsedPkg) {
|
|
47
|
-
return this._parsedPkg
|
|
48
|
-
}
|
|
49
|
-
const packagePath = this.buildPath()
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const contents = fs.readFileSync(packagePath).toString()
|
|
53
|
-
const parsed = JSON.parse(contents)
|
|
54
|
-
this._parsedPkg = parsed
|
|
55
|
-
|
|
56
|
-
return parsed
|
|
57
|
-
} catch (err: any) {
|
|
58
|
-
throw new SpruceError({
|
|
59
|
-
code: 'FAILED_TO_IMPORT',
|
|
60
|
-
file: packagePath,
|
|
61
|
-
originalError: err,
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private buildPath() {
|
|
67
|
-
return pathUtil.join(this.cwd, 'package.json')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public isInstalled(pkg: string) {
|
|
71
|
-
try {
|
|
72
|
-
const contents = this.readPackage()
|
|
73
|
-
|
|
74
|
-
return !!contents.dependencies?.[pkg] || !!contents.devDependencies?.[pkg]
|
|
75
|
-
} catch (e) {
|
|
76
|
-
return false
|
|
77
|
-
}
|
|
18
|
+
public constructor(cwd: string, commandService: CommandService) {
|
|
19
|
+
super(cwd)
|
|
20
|
+
this.commandService = commandService
|
|
78
21
|
}
|
|
79
22
|
|
|
80
23
|
public async install(pkg?: string[] | string, options?: AddOptions) {
|
|
@@ -84,7 +27,7 @@ export default class PkgService extends CommandService {
|
|
|
84
27
|
: () => {}
|
|
85
28
|
|
|
86
29
|
if (!pkg) {
|
|
87
|
-
await this.execute('yarn', { args: ['install'] })
|
|
30
|
+
await this.commandService.execute('yarn', { args: ['install'] })
|
|
88
31
|
deleteLockFile()
|
|
89
32
|
return { totalInstalled: -1, totalSkipped: -1 }
|
|
90
33
|
}
|
|
@@ -115,13 +58,13 @@ export default class PkgService extends CommandService {
|
|
|
115
58
|
options
|
|
116
59
|
)
|
|
117
60
|
|
|
118
|
-
await this.execute(executable, {
|
|
61
|
+
await this.commandService.execute(executable, {
|
|
119
62
|
args,
|
|
120
63
|
})
|
|
121
64
|
} else if (
|
|
122
65
|
!diskUtil.doesDirExist(pathUtil.join(this.cwd, 'node_modules'))
|
|
123
66
|
) {
|
|
124
|
-
await this.execute('yarn', { args: ['install'] })
|
|
67
|
+
await this.commandService.execute('yarn', { args: ['install'] })
|
|
125
68
|
}
|
|
126
69
|
|
|
127
70
|
deleteLockFile()
|
|
@@ -150,20 +93,10 @@ export default class PkgService extends CommandService {
|
|
|
150
93
|
return { executable, args }
|
|
151
94
|
}
|
|
152
95
|
|
|
153
|
-
public deleteLockFile() {
|
|
154
|
-
const files = ['package-lock.json', 'yarn.lock']
|
|
155
|
-
for (const file of files) {
|
|
156
|
-
const lock = pathUtil.join(this.cwd, file)
|
|
157
|
-
if (diskUtil.doesFileExist(lock)) {
|
|
158
|
-
diskUtil.deleteFile(lock)
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
96
|
public async uninstall(pkg: string[] | string) {
|
|
164
97
|
const packages = Array.isArray(pkg) ? pkg : [pkg]
|
|
165
98
|
const args: string[] = ['uninstall', ...packages]
|
|
166
|
-
await this.execute('npm', {
|
|
99
|
+
await this.commandService.execute('npm', {
|
|
167
100
|
args,
|
|
168
101
|
})
|
|
169
102
|
|
|
@@ -171,17 +104,4 @@ export default class PkgService extends CommandService {
|
|
|
171
104
|
|
|
172
105
|
await this.install()
|
|
173
106
|
}
|
|
174
|
-
|
|
175
|
-
public stripLatest(name: string): string {
|
|
176
|
-
return name.replace('@latest', '')
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public buildPackageName(dep: NpmPackage): string {
|
|
180
|
-
const { name, version } = dep
|
|
181
|
-
if (!version) {
|
|
182
|
-
return name
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return `${name}@${version}`
|
|
186
|
-
}
|
|
187
107
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SettingsService,
|
|
3
|
+
EnvService,
|
|
4
|
+
AuthService,
|
|
5
|
+
} from '@sprucelabs/spruce-skill-utils'
|
|
2
6
|
import EventSettingsService from '../features/event/services/EventSettingsService'
|
|
3
7
|
import RemoteService from '../features/event/services/RemoteService'
|
|
4
8
|
import { FeatureCode } from '../features/features.types'
|
|
5
9
|
import SchemaService from '../features/schema/services/SchemaService'
|
|
6
10
|
import VsCodeService from '../features/vscode/services/VsCodeService'
|
|
7
|
-
import AuthService from './AuthService'
|
|
8
11
|
import BuildService from './BuildService'
|
|
9
12
|
import CommandService from './CommandService'
|
|
10
13
|
import DependencyService from './DependencyService'
|
|
@@ -39,12 +42,12 @@ export default class ServiceFactory {
|
|
|
39
42
|
public Service<S extends Service>(cwd: string, type: S): ServiceMap[S] {
|
|
40
43
|
switch (type) {
|
|
41
44
|
case 'auth':
|
|
42
|
-
return
|
|
43
|
-
new EnvService(cwd),
|
|
44
|
-
new PkgService(cwd)
|
|
45
|
-
) as ServiceMap[S]
|
|
45
|
+
return AuthService.Auth(cwd) as ServiceMap[S]
|
|
46
46
|
case 'pkg':
|
|
47
|
-
return new PkgService(
|
|
47
|
+
return new PkgService(
|
|
48
|
+
cwd,
|
|
49
|
+
this.Service(cwd, 'command')
|
|
50
|
+
) as ServiceMap[S]
|
|
48
51
|
case 'env':
|
|
49
52
|
return new EnvService(cwd) as ServiceMap[S]
|
|
50
53
|
case 'vsCode':
|
package/src/types/cli.types.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
FeatureActionResponse,
|
|
5
5
|
} from '../features/features.types'
|
|
6
6
|
import { GraphicsInterface as IGraphicsInterface } from './graphicsInterface.types'
|
|
7
|
+
export { NpmPackage } from '@sprucelabs/spruce-skill-utils'
|
|
7
8
|
|
|
8
9
|
export interface GraphicsInterface extends IGraphicsInterface {
|
|
9
10
|
renderActionSummary(results: ExecutionResults & { totalTime?: number }): void
|
|
@@ -20,12 +21,6 @@ export type GeneratedDir = SpruceSchemas.SpruceCli.v2020_07_22.GeneratedDir
|
|
|
20
21
|
export type GeneratedFileOrDir =
|
|
21
22
|
SpruceSchemas.SpruceCli.v2020_07_22.WatcherDidDetectChangesEmitPayload['changes'][number]
|
|
22
23
|
|
|
23
|
-
export interface NpmPackage {
|
|
24
|
-
name: string
|
|
25
|
-
version?: string
|
|
26
|
-
isDev?: boolean
|
|
27
|
-
}
|
|
28
|
-
|
|
29
24
|
export interface ExecutionResults extends FeatureActionResponse {
|
|
30
25
|
featureCode: string
|
|
31
26
|
actionCode: string
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import AbstractCliTest from '../../tests/AbstractCliTest';
|
|
2
|
-
export default class AuthServiceTest extends AbstractCliTest {
|
|
3
|
-
private static auth;
|
|
4
|
-
protected static beforeEach(): Promise<void>;
|
|
5
|
-
protected static canInstantiatePersonStore(): Promise<void>;
|
|
6
|
-
protected static hasLoggedInPersonMethod(): Promise<void>;
|
|
7
|
-
protected static loggedInPersonIsNullWhenNotLoggedIn(): Promise<void>;
|
|
8
|
-
protected static cantSaveBadLoggedInPerson(): Promise<void>;
|
|
9
|
-
protected static canSaveLoggedInPerson(): void;
|
|
10
|
-
protected static canLogOut(): void;
|
|
11
|
-
protected static getCurrentSkillReturnsNull(): void;
|
|
12
|
-
protected static canSetCurrentSkill(): void;
|
|
13
|
-
private static writePackageJson;
|
|
14
|
-
}
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
|
-
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
19
|
-
|
|
20
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
-
|
|
22
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
-
|
|
24
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
-
|
|
26
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
27
|
-
|
|
28
|
-
var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
|
|
29
|
-
|
|
30
|
-
var _spruceSkillUtils = require("@sprucelabs/spruce-skill-utils");
|
|
31
|
-
|
|
32
|
-
var _test = require("@sprucelabs/test");
|
|
33
|
-
|
|
34
|
-
var _testUtils = require("@sprucelabs/test-utils");
|
|
35
|
-
|
|
36
|
-
var _AbstractCliTest2 = _interopRequireDefault(require("../../tests/AbstractCliTest"));
|
|
37
|
-
|
|
38
|
-
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2, _temp;
|
|
39
|
-
|
|
40
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
41
|
-
|
|
42
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
43
|
-
|
|
44
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
45
|
-
|
|
46
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
47
|
-
|
|
48
|
-
var AuthServiceTest = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(), _dec3 = (0, _test.test)(), _dec4 = (0, _test.test)(), _dec5 = (0, _test.test)(), _dec6 = (0, _test.test)(), _dec7 = (0, _test.test)(), _dec8 = (0, _test.test)(), (_class = (_temp = _class2 = /*#__PURE__*/function (_AbstractCliTest) {
|
|
49
|
-
(0, _inherits2["default"])(AuthServiceTest, _AbstractCliTest);
|
|
50
|
-
|
|
51
|
-
var _super = _createSuper(AuthServiceTest);
|
|
52
|
-
|
|
53
|
-
function AuthServiceTest() {
|
|
54
|
-
(0, _classCallCheck2["default"])(this, AuthServiceTest);
|
|
55
|
-
return _super.apply(this, arguments);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
(0, _createClass2["default"])(AuthServiceTest, null, [{
|
|
59
|
-
key: "beforeEach",
|
|
60
|
-
value: function () {
|
|
61
|
-
var _beforeEach = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
62
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
63
|
-
while (1) {
|
|
64
|
-
switch (_context.prev = _context.next) {
|
|
65
|
-
case 0:
|
|
66
|
-
_context.next = 2;
|
|
67
|
-
return (0, _get2["default"])((0, _getPrototypeOf2["default"])(AuthServiceTest), "beforeEach", this).call(this);
|
|
68
|
-
|
|
69
|
-
case 2:
|
|
70
|
-
_spruceSkillUtils.diskUtil.createDir(this.resolvePath(_spruceSkillUtils.HASH_SPRUCE_DIR));
|
|
71
|
-
|
|
72
|
-
this.auth = this.Service('auth');
|
|
73
|
-
|
|
74
|
-
case 4:
|
|
75
|
-
case "end":
|
|
76
|
-
return _context.stop();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}, _callee, this);
|
|
80
|
-
}));
|
|
81
|
-
|
|
82
|
-
function beforeEach() {
|
|
83
|
-
return _beforeEach.apply(this, arguments);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return beforeEach;
|
|
87
|
-
}()
|
|
88
|
-
}, {
|
|
89
|
-
key: "canInstantiatePersonStore",
|
|
90
|
-
value: function () {
|
|
91
|
-
var _canInstantiatePersonStore = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
92
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
93
|
-
while (1) {
|
|
94
|
-
switch (_context2.prev = _context2.next) {
|
|
95
|
-
case 0:
|
|
96
|
-
_test.assert.isTruthy(this.auth);
|
|
97
|
-
|
|
98
|
-
case 1:
|
|
99
|
-
case "end":
|
|
100
|
-
return _context2.stop();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}, _callee2, this);
|
|
104
|
-
}));
|
|
105
|
-
|
|
106
|
-
function canInstantiatePersonStore() {
|
|
107
|
-
return _canInstantiatePersonStore.apply(this, arguments);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return canInstantiatePersonStore;
|
|
111
|
-
}()
|
|
112
|
-
}, {
|
|
113
|
-
key: "hasLoggedInPersonMethod",
|
|
114
|
-
value: function () {
|
|
115
|
-
var _hasLoggedInPersonMethod = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
116
|
-
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
117
|
-
while (1) {
|
|
118
|
-
switch (_context3.prev = _context3.next) {
|
|
119
|
-
case 0:
|
|
120
|
-
_test.assert.isFunction(this.auth.getLoggedInPerson);
|
|
121
|
-
|
|
122
|
-
case 1:
|
|
123
|
-
case "end":
|
|
124
|
-
return _context3.stop();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}, _callee3, this);
|
|
128
|
-
}));
|
|
129
|
-
|
|
130
|
-
function hasLoggedInPersonMethod() {
|
|
131
|
-
return _hasLoggedInPersonMethod.apply(this, arguments);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return hasLoggedInPersonMethod;
|
|
135
|
-
}()
|
|
136
|
-
}, {
|
|
137
|
-
key: "loggedInPersonIsNullWhenNotLoggedIn",
|
|
138
|
-
value: function () {
|
|
139
|
-
var _loggedInPersonIsNullWhenNotLoggedIn = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
140
|
-
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
141
|
-
while (1) {
|
|
142
|
-
switch (_context4.prev = _context4.next) {
|
|
143
|
-
case 0:
|
|
144
|
-
_test.assert.isNull(this.auth.getLoggedInPerson());
|
|
145
|
-
|
|
146
|
-
case 1:
|
|
147
|
-
case "end":
|
|
148
|
-
return _context4.stop();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}, _callee4, this);
|
|
152
|
-
}));
|
|
153
|
-
|
|
154
|
-
function loggedInPersonIsNullWhenNotLoggedIn() {
|
|
155
|
-
return _loggedInPersonIsNullWhenNotLoggedIn.apply(this, arguments);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return loggedInPersonIsNullWhenNotLoggedIn;
|
|
159
|
-
}()
|
|
160
|
-
}, {
|
|
161
|
-
key: "cantSaveBadLoggedInPerson",
|
|
162
|
-
value: function () {
|
|
163
|
-
var _cantSaveBadLoggedInPerson = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
|
|
164
|
-
var _this = this;
|
|
165
|
-
|
|
166
|
-
var err;
|
|
167
|
-
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
168
|
-
while (1) {
|
|
169
|
-
switch (_context5.prev = _context5.next) {
|
|
170
|
-
case 0:
|
|
171
|
-
err = _test.assert.doesThrow(function () {
|
|
172
|
-
return (//@ts-ignore
|
|
173
|
-
_this.auth.setLoggedInPerson({
|
|
174
|
-
test: true
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
_testUtils.errorAssertUtil.assertError(err, 'MISSING_PARAMETERS');
|
|
180
|
-
|
|
181
|
-
case 2:
|
|
182
|
-
case "end":
|
|
183
|
-
return _context5.stop();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}, _callee5);
|
|
187
|
-
}));
|
|
188
|
-
|
|
189
|
-
function cantSaveBadLoggedInPerson() {
|
|
190
|
-
return _cantSaveBadLoggedInPerson.apply(this, arguments);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return cantSaveBadLoggedInPerson;
|
|
194
|
-
}()
|
|
195
|
-
}, {
|
|
196
|
-
key: "canSaveLoggedInPerson",
|
|
197
|
-
value: function canSaveLoggedInPerson() {
|
|
198
|
-
var auth = this.auth;
|
|
199
|
-
var person = {
|
|
200
|
-
id: 'test',
|
|
201
|
-
casualName: 'friend',
|
|
202
|
-
token: 'token'
|
|
203
|
-
};
|
|
204
|
-
auth.setLoggedInPerson(person);
|
|
205
|
-
var loggedIn = auth.getLoggedInPerson();
|
|
206
|
-
|
|
207
|
-
_test.assert.isEqualDeep(loggedIn, _objectSpread(_objectSpread({}, person), {}, {
|
|
208
|
-
isLoggedIn: true
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
}, {
|
|
212
|
-
key: "canLogOut",
|
|
213
|
-
value: function canLogOut() {
|
|
214
|
-
var auth = this.auth;
|
|
215
|
-
var person = {
|
|
216
|
-
id: 'test',
|
|
217
|
-
casualName: 'friend',
|
|
218
|
-
token: 'token'
|
|
219
|
-
};
|
|
220
|
-
auth.setLoggedInPerson(person);
|
|
221
|
-
auth.logOutPerson();
|
|
222
|
-
|
|
223
|
-
_test.assert.isNull(auth.getLoggedInPerson());
|
|
224
|
-
}
|
|
225
|
-
}, {
|
|
226
|
-
key: "getCurrentSkillReturnsNull",
|
|
227
|
-
value: function getCurrentSkillReturnsNull() {
|
|
228
|
-
this.writePackageJson();
|
|
229
|
-
|
|
230
|
-
_test.assert.isNull(this.auth.getCurrentSkill());
|
|
231
|
-
}
|
|
232
|
-
}, {
|
|
233
|
-
key: "canSetCurrentSkill",
|
|
234
|
-
value: function canSetCurrentSkill() {
|
|
235
|
-
this.writePackageJson();
|
|
236
|
-
var skill = {
|
|
237
|
-
id: '123467aaoeuaoeu',
|
|
238
|
-
apiKey: 'taco',
|
|
239
|
-
name: 'go team',
|
|
240
|
-
slug: 'taco-bravo'
|
|
241
|
-
};
|
|
242
|
-
this.auth.updateCurrentSkill(skill);
|
|
243
|
-
|
|
244
|
-
_test.assert.isEqualDeep(this.auth.getCurrentSkill(), skill);
|
|
245
|
-
}
|
|
246
|
-
}, {
|
|
247
|
-
key: "writePackageJson",
|
|
248
|
-
value: function writePackageJson() {
|
|
249
|
-
_spruceSkillUtils.diskUtil.writeFile(this.resolvePath('package.json'), '{}');
|
|
250
|
-
}
|
|
251
|
-
}]);
|
|
252
|
-
return AuthServiceTest;
|
|
253
|
-
}(_AbstractCliTest2["default"]), (0, _defineProperty2["default"])(_class2, "auth", void 0), _temp), ((0, _applyDecoratedDescriptor2["default"])(_class, "canInstantiatePersonStore", [_dec], Object.getOwnPropertyDescriptor(_class, "canInstantiatePersonStore"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "hasLoggedInPersonMethod", [_dec2], Object.getOwnPropertyDescriptor(_class, "hasLoggedInPersonMethod"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "loggedInPersonIsNullWhenNotLoggedIn", [_dec3], Object.getOwnPropertyDescriptor(_class, "loggedInPersonIsNullWhenNotLoggedIn"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "cantSaveBadLoggedInPerson", [_dec4], Object.getOwnPropertyDescriptor(_class, "cantSaveBadLoggedInPerson"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "canSaveLoggedInPerson", [_dec5], Object.getOwnPropertyDescriptor(_class, "canSaveLoggedInPerson"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "canLogOut", [_dec6], Object.getOwnPropertyDescriptor(_class, "canLogOut"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "getCurrentSkillReturnsNull", [_dec7], Object.getOwnPropertyDescriptor(_class, "getCurrentSkillReturnsNull"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "canSetCurrentSkill", [_dec8], Object.getOwnPropertyDescriptor(_class, "canSetCurrentSkill"), _class)), _class));
|
|
254
|
-
exports["default"] = AuthServiceTest;
|
|
255
|
-
//# sourceMappingURL=AuthService.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/__tests__/implementation/AuthService.test.ts"],"names":["AuthServiceTest","diskUtil","createDir","resolvePath","HASH_SPRUCE_DIR","auth","Service","assert","isTruthy","isFunction","getLoggedInPerson","isNull","err","doesThrow","setLoggedInPerson","test","errorAssertUtil","assertError","person","id","casualName","token","loggedIn","isEqualDeep","isLoggedIn","logOutPerson","writePackageJson","getCurrentSkill","skill","apiKey","name","slug","updateCurrentSkill","writeFile","AbstractCliTest"],"mappings":"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","sourcesContent":["import { diskUtil, HASH_SPRUCE_DIR } from '@sprucelabs/spruce-skill-utils'\nimport { test, assert } from '@sprucelabs/test'\nimport { errorAssertUtil } from '@sprucelabs/test-utils'\nimport AuthService from '../../services/AuthService'\nimport AbstractCliTest from '../../tests/AbstractCliTest'\n\nexport default class AuthServiceTest extends AbstractCliTest {\n\tprivate static auth: AuthService\n\tprotected static async beforeEach() {\n\t\tawait super.beforeEach()\n\t\tdiskUtil.createDir(this.resolvePath(HASH_SPRUCE_DIR))\n\t\tthis.auth = this.Service('auth')\n\t}\n\n\t@test()\n\tprotected static async canInstantiatePersonStore() {\n\t\tassert.isTruthy(this.auth)\n\t}\n\n\t@test()\n\tprotected static async hasLoggedInPersonMethod() {\n\t\tassert.isFunction(this.auth.getLoggedInPerson)\n\t}\n\n\t@test()\n\tprotected static async loggedInPersonIsNullWhenNotLoggedIn() {\n\t\tassert.isNull(this.auth.getLoggedInPerson())\n\t}\n\n\t@test()\n\tprotected static async cantSaveBadLoggedInPerson() {\n\t\tconst err = assert.doesThrow(() =>\n\t\t\t//@ts-ignore\n\t\t\tthis.auth.setLoggedInPerson({ test: true })\n\t\t)\n\n\t\terrorAssertUtil.assertError(err, 'MISSING_PARAMETERS')\n\t}\n\n\t@test()\n\tprotected static canSaveLoggedInPerson() {\n\t\tconst auth = this.auth\n\t\tconst person = {\n\t\t\tid: 'test',\n\t\t\tcasualName: 'friend',\n\t\t\ttoken: 'token',\n\t\t}\n\n\t\tauth.setLoggedInPerson(person)\n\n\t\tconst loggedIn = auth.getLoggedInPerson()\n\n\t\tassert.isEqualDeep(loggedIn, { ...person, isLoggedIn: true })\n\t}\n\n\t@test()\n\tprotected static canLogOut() {\n\t\tconst auth = this.auth\n\t\tconst person = {\n\t\t\tid: 'test',\n\t\t\tcasualName: 'friend',\n\t\t\ttoken: 'token',\n\t\t}\n\n\t\tauth.setLoggedInPerson(person)\n\t\tauth.logOutPerson()\n\n\t\tassert.isNull(auth.getLoggedInPerson())\n\t}\n\n\t@test()\n\tprotected static getCurrentSkillReturnsNull() {\n\t\tthis.writePackageJson()\n\t\tassert.isNull(this.auth.getCurrentSkill())\n\t}\n\n\t@test()\n\tprotected static canSetCurrentSkill() {\n\t\tthis.writePackageJson()\n\t\tconst skill = {\n\t\t\tid: '123467aaoeuaoeu',\n\t\t\tapiKey: 'taco',\n\t\t\tname: 'go team',\n\t\t\tslug: 'taco-bravo',\n\t\t}\n\n\t\tthis.auth.updateCurrentSkill(skill)\n\n\t\tassert.isEqualDeep(this.auth.getCurrentSkill(), skill)\n\t}\n\n\tprivate static writePackageJson() {\n\t\tdiskUtil.writeFile(this.resolvePath('package.json'), '{}')\n\t}\n}\n"],"file":"AuthService.test.js"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { SpruceSchemas } from '@sprucelabs/mercury-types';
|
|
2
|
-
import { EnvService } from '@sprucelabs/spruce-skill-utils';
|
|
3
|
-
import PkgService from './PkgService';
|
|
4
|
-
declare type PersonWithToken = SpruceSchemas.SpruceCli.v2020_07_22.PersonWithToken;
|
|
5
|
-
export interface SkillAuth {
|
|
6
|
-
id: string;
|
|
7
|
-
apiKey: string;
|
|
8
|
-
name: string;
|
|
9
|
-
slug: string;
|
|
10
|
-
}
|
|
11
|
-
export default class AuthService {
|
|
12
|
-
private env;
|
|
13
|
-
private pkg;
|
|
14
|
-
constructor(envService: EnvService, pkgService: PkgService);
|
|
15
|
-
getLoggedInPerson(): PersonWithToken | null;
|
|
16
|
-
setLoggedInPerson(person: PersonWithToken): void;
|
|
17
|
-
logOutPerson(): void;
|
|
18
|
-
getCurrentSkill(): SkillAuth | null;
|
|
19
|
-
logoutCurrentSkill(): void;
|
|
20
|
-
updateCurrentSkill(skill: SkillAuth): void;
|
|
21
|
-
updateCurrentSkillNamespace(namespace: string): void;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _schema = require("@sprucelabs/schema");
|
|
17
|
-
|
|
18
|
-
var _spruceSkillUtils = require("@sprucelabs/spruce-skill-utils");
|
|
19
|
-
|
|
20
|
-
var _personWithToken = _interopRequireDefault(require("../.spruce/schemas/spruceCli/v2020_07_22/personWithToken.schema"));
|
|
21
|
-
|
|
22
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
25
|
-
|
|
26
|
-
var LOGGED_IN_PERSON_KEY = 'LOGGED_IN_PERSON';
|
|
27
|
-
|
|
28
|
-
var AuthService = /*#__PURE__*/function () {
|
|
29
|
-
function AuthService(envService, pkgService) {
|
|
30
|
-
(0, _classCallCheck2["default"])(this, AuthService);
|
|
31
|
-
(0, _defineProperty2["default"])(this, "env", void 0);
|
|
32
|
-
(0, _defineProperty2["default"])(this, "pkg", void 0);
|
|
33
|
-
this.env = envService;
|
|
34
|
-
this.pkg = pkgService;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
(0, _createClass2["default"])(AuthService, [{
|
|
38
|
-
key: "getLoggedInPerson",
|
|
39
|
-
value: function getLoggedInPerson() {
|
|
40
|
-
var p = this.env.get(LOGGED_IN_PERSON_KEY);
|
|
41
|
-
|
|
42
|
-
if (typeof p === 'string') {
|
|
43
|
-
return JSON.parse(p);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}, {
|
|
49
|
-
key: "setLoggedInPerson",
|
|
50
|
-
value: function setLoggedInPerson(person) {
|
|
51
|
-
var normalized = (0, _schema.normalizeSchemaValues)(_personWithToken["default"], person);
|
|
52
|
-
(0, _schema.validateSchemaValues)(_personWithToken["default"], normalized);
|
|
53
|
-
this.env.set(LOGGED_IN_PERSON_KEY, JSON.stringify(_objectSpread(_objectSpread({}, normalized), {}, {
|
|
54
|
-
isLoggedIn: true
|
|
55
|
-
})));
|
|
56
|
-
}
|
|
57
|
-
}, {
|
|
58
|
-
key: "logOutPerson",
|
|
59
|
-
value: function logOutPerson() {
|
|
60
|
-
this.env.unset(LOGGED_IN_PERSON_KEY);
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
key: "getCurrentSkill",
|
|
64
|
-
value: function getCurrentSkill() {
|
|
65
|
-
var id = this.env.get('SKILL_ID');
|
|
66
|
-
var apiKey = this.env.get('SKILL_API_KEY');
|
|
67
|
-
var name = this.env.get('SKILL_NAME');
|
|
68
|
-
var slug = this.pkg.get('skill.namespace');
|
|
69
|
-
|
|
70
|
-
if (id && apiKey) {
|
|
71
|
-
return {
|
|
72
|
-
id: id,
|
|
73
|
-
apiKey: apiKey,
|
|
74
|
-
name: name,
|
|
75
|
-
slug: slug
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "logoutCurrentSkill",
|
|
83
|
-
value: function logoutCurrentSkill() {
|
|
84
|
-
this.env.unset('SKILL_ID');
|
|
85
|
-
this.env.unset('SKILL_API_KEY');
|
|
86
|
-
this.env.unset('SKILL_NAME');
|
|
87
|
-
}
|
|
88
|
-
}, {
|
|
89
|
-
key: "updateCurrentSkill",
|
|
90
|
-
value: function updateCurrentSkill(skill) {
|
|
91
|
-
this.env.set('SKILL_ID', skill.id);
|
|
92
|
-
this.env.set('SKILL_API_KEY', skill.apiKey);
|
|
93
|
-
this.env.set('SKILL_NAME', skill.name);
|
|
94
|
-
this.updateCurrentSkillNamespace(skill.slug);
|
|
95
|
-
}
|
|
96
|
-
}, {
|
|
97
|
-
key: "updateCurrentSkillNamespace",
|
|
98
|
-
value: function updateCurrentSkillNamespace(namespace) {
|
|
99
|
-
this.pkg.set({
|
|
100
|
-
path: 'skill.namespace',
|
|
101
|
-
value: _spruceSkillUtils.namesUtil.toKebab(namespace)
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}]);
|
|
105
|
-
return AuthService;
|
|
106
|
-
}();
|
|
107
|
-
|
|
108
|
-
exports["default"] = AuthService;
|
|
109
|
-
//# sourceMappingURL=AuthService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/AuthService.ts"],"names":["LOGGED_IN_PERSON_KEY","AuthService","envService","pkgService","env","pkg","p","get","JSON","parse","person","normalized","personWithTokenSchema","set","stringify","isLoggedIn","unset","id","apiKey","name","slug","skill","updateCurrentSkillNamespace","namespace","path","value","namesUtil","toKebab"],"mappings":";;;;;;;;;;;;;;;AACA;;AACA;;AACA;;;;;;AAYA,IAAMA,oBAAoB,GAAG,kBAA7B;;IAEqBC,W;AAIpB,uBAAmBC,UAAnB,EAA2CC,UAA3C,EAAmE;AAAA;AAAA;AAAA;AAClE,SAAKC,GAAL,GAAWF,UAAX;AACA,SAAKG,GAAL,GAAWF,UAAX;AACA;;;;WAED,6BAAmD;AAClD,UAAMG,CAAC,GAAG,KAAKF,GAAL,CAASG,GAAT,CAAaP,oBAAb,CAAV;;AACA,UAAI,OAAOM,CAAP,KAAa,QAAjB,EAA2B;AAC1B,eAAOE,IAAI,CAACC,KAAL,CAAWH,CAAX,CAAP;AACA;;AAED,aAAO,IAAP;AACA;;;WAED,2BAAyBI,MAAzB,EAAkD;AACjD,UAAMC,UAAU,GAAG,mCAAsBC,2BAAtB,EAA6CF,MAA7C,CAAnB;AACA,wCAAqBE,2BAArB,EAA4CD,UAA5C;AAEA,WAAKP,GAAL,CAASS,GAAT,CACCb,oBADD,EAECQ,IAAI,CAACM,SAAL,iCACIH,UADJ;AAECI,QAAAA,UAAU,EAAE;AAFb,SAFD;AAOA;;;WAED,wBAAsB;AACrB,WAAKX,GAAL,CAASY,KAAT,CAAehB,oBAAf;AACA;;;WAED,2BAA2C;AAC1C,UAAMiB,EAAE,GAAG,KAAKb,GAAL,CAASG,GAAT,CAAa,UAAb,CAAX;AACA,UAAMW,MAAM,GAAG,KAAKd,GAAL,CAASG,GAAT,CAAa,eAAb,CAAf;AACA,UAAMY,IAAI,GAAG,KAAKf,GAAL,CAASG,GAAT,CAAa,YAAb,CAAb;AACA,UAAMa,IAAI,GAAG,KAAKf,GAAL,CAASE,GAAT,CAAa,iBAAb,CAAb;;AAEA,UAAIU,EAAE,IAAIC,MAAV,EAAkB;AACjB,eAAO;AACND,UAAAA,EAAE,EAAFA,EADM;AAENC,UAAAA,MAAM,EAANA,MAFM;AAGNC,UAAAA,IAAI,EAAJA,IAHM;AAINC,UAAAA,IAAI,EAAJA;AAJM,SAAP;AAMA;;AAED,aAAO,IAAP;AACA;;;WAED,8BAA4B;AAC3B,WAAKhB,GAAL,CAASY,KAAT,CAAe,UAAf;AACA,WAAKZ,GAAL,CAASY,KAAT,CAAe,eAAf;AACA,WAAKZ,GAAL,CAASY,KAAT,CAAe,YAAf;AACA;;;WAED,4BAA0BK,KAA1B,EAA4C;AAC3C,WAAKjB,GAAL,CAASS,GAAT,CAAa,UAAb,EAAyBQ,KAAK,CAACJ,EAA/B;AACA,WAAKb,GAAL,CAASS,GAAT,CAAa,eAAb,EAA8BQ,KAAK,CAACH,MAApC;AACA,WAAKd,GAAL,CAASS,GAAT,CAAa,YAAb,EAA2BQ,KAAK,CAACF,IAAjC;AAEA,WAAKG,2BAAL,CAAiCD,KAAK,CAACD,IAAvC;AACA;;;WAED,qCAAmCG,SAAnC,EAAsD;AACrD,WAAKlB,GAAL,CAASQ,GAAT,CAAa;AACZW,QAAAA,IAAI,EAAE,iBADM;AAEZC,QAAAA,KAAK,EAAEC,4BAAUC,OAAV,CAAkBJ,SAAlB;AAFK,OAAb;AAIA","sourcesContent":["import { SpruceSchemas } from '@sprucelabs/mercury-types'\nimport { normalizeSchemaValues, validateSchemaValues } from '@sprucelabs/schema'\nimport { EnvService, namesUtil } from '@sprucelabs/spruce-skill-utils'\nimport personWithTokenSchema from '#spruce/schemas/spruceCli/v2020_07_22/personWithToken.schema'\nimport PkgService from './PkgService'\n\ntype PersonWithToken = SpruceSchemas.SpruceCli.v2020_07_22.PersonWithToken\n\nexport interface SkillAuth {\n\tid: string\n\tapiKey: string\n\tname: string\n\tslug: string\n}\n\nconst LOGGED_IN_PERSON_KEY = 'LOGGED_IN_PERSON'\n\nexport default class AuthService {\n\tprivate env: EnvService\n\tprivate pkg: PkgService\n\n\tpublic constructor(envService: EnvService, pkgService: PkgService) {\n\t\tthis.env = envService\n\t\tthis.pkg = pkgService\n\t}\n\n\tpublic getLoggedInPerson(): PersonWithToken | null {\n\t\tconst p = this.env.get(LOGGED_IN_PERSON_KEY)\n\t\tif (typeof p === 'string') {\n\t\t\treturn JSON.parse(p)\n\t\t}\n\n\t\treturn null\n\t}\n\n\tpublic setLoggedInPerson(person: PersonWithToken) {\n\t\tconst normalized = normalizeSchemaValues(personWithTokenSchema, person)\n\t\tvalidateSchemaValues(personWithTokenSchema, normalized)\n\n\t\tthis.env.set(\n\t\t\tLOGGED_IN_PERSON_KEY,\n\t\t\tJSON.stringify({\n\t\t\t\t...normalized,\n\t\t\t\tisLoggedIn: true,\n\t\t\t})\n\t\t)\n\t}\n\n\tpublic logOutPerson() {\n\t\tthis.env.unset(LOGGED_IN_PERSON_KEY)\n\t}\n\n\tpublic getCurrentSkill(): SkillAuth | null {\n\t\tconst id = this.env.get('SKILL_ID') as string\n\t\tconst apiKey = this.env.get('SKILL_API_KEY') as string\n\t\tconst name = this.env.get('SKILL_NAME') as string\n\t\tconst slug = this.pkg.get('skill.namespace') as string\n\n\t\tif (id && apiKey) {\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\tapiKey,\n\t\t\t\tname,\n\t\t\t\tslug,\n\t\t\t}\n\t\t}\n\n\t\treturn null\n\t}\n\n\tpublic logoutCurrentSkill() {\n\t\tthis.env.unset('SKILL_ID')\n\t\tthis.env.unset('SKILL_API_KEY')\n\t\tthis.env.unset('SKILL_NAME')\n\t}\n\n\tpublic updateCurrentSkill(skill: SkillAuth) {\n\t\tthis.env.set('SKILL_ID', skill.id)\n\t\tthis.env.set('SKILL_API_KEY', skill.apiKey)\n\t\tthis.env.set('SKILL_NAME', skill.name)\n\n\t\tthis.updateCurrentSkillNamespace(skill.slug)\n\t}\n\n\tpublic updateCurrentSkillNamespace(namespace: string) {\n\t\tthis.pkg.set({\n\t\t\tpath: 'skill.namespace',\n\t\t\tvalue: namesUtil.toKebab(namespace),\n\t\t})\n\t}\n}\n"],"file":"AuthService.js"}
|