@sprucelabs/spruce-cli 14.29.3 → 14.29.7

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.
Files changed (144) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/build/GlobalEmitter.js +2 -2
  3. package/build/__tests__/behavioral/InstallingASkillAtAnOrg.test.d.ts +1 -1
  4. package/build/__tests__/behavioral/InstallingASkillAtAnOrg.test.js +93 -93
  5. package/build/__tests__/behavioral/InstallingASkillAtAnOrg.test.js.map +1 -1
  6. package/build/__tests__/behavioral/SettingUpSchemasForModuleDistribution.test.js +2 -2
  7. package/build/__tests__/behavioral/events/CreatingAnEvent.test.js +2 -2
  8. package/build/__tests__/behavioral/events/KeepingEventsInSync2.test.js +2 -2
  9. package/build/__tests__/behavioral/views/CreatingASkillView.test.d.ts +1 -0
  10. package/build/__tests__/behavioral/views/CreatingASkillView.test.js +35 -3
  11. package/build/__tests__/behavioral/views/CreatingASkillView.test.js.map +1 -1
  12. package/build/__tests__/implementation/EventContractCleanerUtil.test.js +2 -2
  13. package/build/__tests__/implementation/EventTemplateItemBuilder.test.js +2 -2
  14. package/build/__tests__/implementation/PkgService.test.js +3 -6
  15. package/build/__tests__/implementation/PkgService.test.js.map +1 -1
  16. package/build/__tests__/implementation/SchemaStore.test.js +2 -2
  17. package/build/__tests__/implementation/SchemaTemplateItemBuilder.test.js +2 -2
  18. package/build/cli.js +11 -9
  19. package/build/cli.js.map +1 -1
  20. package/build/components/AbstractComponent.js +2 -2
  21. package/build/components/FormComponent.js +2 -2
  22. package/build/components/QuizComponent.js +2 -2
  23. package/build/features/AbstractAction.js +2 -2
  24. package/build/features/AbstractFeature.js +2 -2
  25. package/build/features/ActionExecuter.js +2 -2
  26. package/build/features/ActionFactory.js +2 -2
  27. package/build/features/ActionQuestionAsker.js +2 -2
  28. package/build/features/FeatureCommandAttacher.js +2 -2
  29. package/build/features/FeatureInstaller.js +2 -2
  30. package/build/features/OverrideActionDecorator.js +2 -2
  31. package/build/features/deploy/actions/HerokuAction.js.map +1 -1
  32. package/build/features/error/actions/CreateAction.js +2 -2
  33. package/build/features/error/actions/SyncAction.js +2 -2
  34. package/build/features/error/writers/ErrorWriter.js +2 -2
  35. package/build/features/event/EventFeature.js.map +1 -1
  36. package/build/features/event/actions/CreateAction.js +2 -2
  37. package/build/features/event/actions/ListenAction.js +2 -2
  38. package/build/features/event/builders/EventContractBuilder.js +2 -2
  39. package/build/features/event/builders/ListenerTemplateItemBuilder.js +2 -2
  40. package/build/features/event/stores/EventStore.js +2 -2
  41. package/build/features/event/stores/ListenerStore.js +2 -2
  42. package/build/features/event/writers/EventWriter.js +2 -2
  43. package/build/features/eventContract/EventContractFeature.js +3 -1
  44. package/build/features/eventContract/EventContractFeature.js.map +1 -1
  45. package/build/features/node/NodeFeature.js +12 -10
  46. package/build/features/node/NodeFeature.js.map +1 -1
  47. package/build/features/node/actions/UpgradeAction.js +10 -9
  48. package/build/features/node/actions/UpgradeAction.js.map +1 -1
  49. package/build/features/node/writers/NodeWriter.js +2 -2
  50. package/build/features/organization/OrganizationFeature.js +3 -1
  51. package/build/features/organization/OrganizationFeature.js.map +1 -1
  52. package/build/features/person/PersonFeature.js +3 -1
  53. package/build/features/person/PersonFeature.js.map +1 -1
  54. package/build/features/person/actions/LoginAction.js +2 -2
  55. package/build/features/sandbox/SandboxFeature.js +3 -1
  56. package/build/features/sandbox/SandboxFeature.js.map +1 -1
  57. package/build/features/schema/actions/CreateAction.js +2 -2
  58. package/build/features/schema/stores/SchemaStore.js +2 -2
  59. package/build/features/schema/utilities/schemaDisk.utility.js +2 -2
  60. package/build/features/schema/writers/SchemaWriter.js +2 -2
  61. package/build/features/skill/SkillFeature.js +2 -2
  62. package/build/features/skill/actions/CreateAction.js +2 -2
  63. package/build/features/skill/actions/RegisterAction.js +1 -0
  64. package/build/features/skill/actions/RegisterAction.js.map +1 -1
  65. package/build/features/skill/stores/SkillStore.js +2 -2
  66. package/build/features/skill/writers/SkillWriter.js +2 -2
  67. package/build/features/store/actions/CreateAction.js +2 -2
  68. package/build/features/test/TestFeature.js +2 -2
  69. package/build/features/test/TestReporter.js +2 -2
  70. package/build/features/test/TestRunner.js +2 -2
  71. package/build/features/test/actions/CreateAction.js +2 -2
  72. package/build/features/validateAndNormalize.utility.js +2 -2
  73. package/build/features/view/actions/CreateAction.js +2 -2
  74. package/build/features/view/writers/ViewWriter.js +2 -2
  75. package/build/features/vscode/VsCodeFeature.js +3 -1
  76. package/build/features/vscode/VsCodeFeature.js.map +1 -1
  77. package/build/interfaces/TerminalInterface.js +2 -2
  78. package/build/schemas/v2020_07_22/createConversationTopicOptions.builder.js +2 -2
  79. package/build/schemas/v2020_07_22/createErrorOptions.builder.js +2 -2
  80. package/build/schemas/v2020_07_22/createOrganizationOptions.builder.js +2 -2
  81. package/build/schemas/v2020_07_22/createSchemaOptions.builder.js +2 -2
  82. package/build/schemas/v2020_07_22/listenEventOptions.builder.js +2 -2
  83. package/build/schemas/v2020_07_22/syncErrorOptions.builder.js +2 -2
  84. package/build/schemas/v2020_07_22/syncSchemasOptions.builder.js +2 -2
  85. package/build/services/CommandService.js +2 -2
  86. package/build/services/PkgService.d.ts +4 -16
  87. package/build/services/PkgService.js +11 -127
  88. package/build/services/PkgService.js.map +1 -1
  89. package/build/services/ServiceFactory.d.ts +1 -2
  90. package/build/services/ServiceFactory.js +2 -4
  91. package/build/services/ServiceFactory.js.map +1 -1
  92. package/build/services/TypeCheckerService.js +4 -3
  93. package/build/services/TypeCheckerService.js.map +1 -1
  94. package/build/stores/AbstractLocalStore.js +2 -2
  95. package/build/templateItemBuilders/EventTemplateItemBuilder.js +2 -2
  96. package/build/templateItemBuilders/SchemaTemplateItemBuilder.js +2 -2
  97. package/build/tests/AbstractCliTest.js +2 -2
  98. package/build/tests/AbstractEventTest.js +2 -2
  99. package/build/tests/AbstractSchemaTest.js +2 -2
  100. package/build/tests/JestJsonParser.js +2 -2
  101. package/build/tests/fixtures/FeatureFixture.js +2 -2
  102. package/build/tests/fixtures/OrganizationFixture.js +2 -2
  103. package/build/tests/fixtures/PersonFixture.js +2 -2
  104. package/build/tests/fixtures/SkillFixture.js +2 -2
  105. package/build/types/cli.types.d.ts +1 -6
  106. package/build/types/cli.types.js +8 -0
  107. package/build/types/cli.types.js.map +1 -1
  108. package/build/updaters/ScriptUpdater.js +2 -2
  109. package/build/utilities/commander.utility.js +2 -2
  110. package/build/utilities/eventContractCleaner.utility.js +2 -2
  111. package/build/widgets/WidgetFactory.js +2 -2
  112. package/build/widgets/terminalKit/TKButtonWidget.js +2 -2
  113. package/build/widgets/terminalKit/TkBaseWidget.js +2 -2
  114. package/build/widgets/terminalKit/TkInputWidget.js +2 -2
  115. package/build/widgets/terminalKit/TkLayoutCellWidget.js +2 -2
  116. package/build/widgets/terminalKit/TkLayoutWidget.js +2 -2
  117. package/build/widgets/terminalKit/TkMenuBarWidget.js +2 -2
  118. package/build/widgets/terminalKit/TkPopupWidget.js +2 -2
  119. package/build/widgets/terminalKit/TkProgressBarWidget.js +2 -2
  120. package/build/widgets/terminalKit/TkTextWidget.js +2 -2
  121. package/build/widgets/terminalKit/termKit.utility.js +2 -2
  122. package/build/writers/AbstractWriter.js +2 -2
  123. package/build/writers/WriterFactory.js +2 -2
  124. package/package.json +38 -38
  125. package/src/__tests__/behavioral/InstallingASkillAtAnOrg.test.ts +6 -6
  126. package/src/__tests__/behavioral/views/CreatingASkillView.test.ts +16 -0
  127. package/src/__tests__/implementation/PkgService.test.ts +1 -2
  128. package/src/cli.ts +4 -1
  129. package/src/features/deploy/actions/HerokuAction.ts +1 -2
  130. package/src/features/event/EventFeature.ts +0 -1
  131. package/src/features/node/NodeFeature.ts +3 -0
  132. package/src/features/node/actions/UpgradeAction.ts +1 -0
  133. package/src/features/skill/actions/RegisterAction.ts +3 -0
  134. package/src/services/PkgService.ts +13 -93
  135. package/src/services/ServiceFactory.ts +10 -7
  136. package/src/types/cli.types.ts +1 -6
  137. package/build/__tests__/implementation/AuthService.test.d.ts +0 -14
  138. package/build/__tests__/implementation/AuthService.test.js +0 -255
  139. package/build/__tests__/implementation/AuthService.test.js.map +0 -1
  140. package/build/services/AuthService.d.ts +0 -23
  141. package/build/services/AuthService.js +0 -109
  142. package/build/services/AuthService.js.map +0 -1
  143. package/src/__tests__/implementation/AuthService.test.ts +0 -95
  144. package/src/services/AuthService.ts +0 -91
@@ -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"}
@@ -1,95 +0,0 @@
1
- import { diskUtil, HASH_SPRUCE_DIR } from '@sprucelabs/spruce-skill-utils'
2
- import { test, assert } from '@sprucelabs/test'
3
- import { errorAssertUtil } from '@sprucelabs/test-utils'
4
- import AuthService from '../../services/AuthService'
5
- import AbstractCliTest from '../../tests/AbstractCliTest'
6
-
7
- export default class AuthServiceTest extends AbstractCliTest {
8
- private static auth: AuthService
9
- protected static async beforeEach() {
10
- await super.beforeEach()
11
- diskUtil.createDir(this.resolvePath(HASH_SPRUCE_DIR))
12
- this.auth = this.Service('auth')
13
- }
14
-
15
- @test()
16
- protected static async canInstantiatePersonStore() {
17
- assert.isTruthy(this.auth)
18
- }
19
-
20
- @test()
21
- protected static async hasLoggedInPersonMethod() {
22
- assert.isFunction(this.auth.getLoggedInPerson)
23
- }
24
-
25
- @test()
26
- protected static async loggedInPersonIsNullWhenNotLoggedIn() {
27
- assert.isNull(this.auth.getLoggedInPerson())
28
- }
29
-
30
- @test()
31
- protected static async cantSaveBadLoggedInPerson() {
32
- const err = assert.doesThrow(() =>
33
- //@ts-ignore
34
- this.auth.setLoggedInPerson({ test: true })
35
- )
36
-
37
- errorAssertUtil.assertError(err, 'MISSING_PARAMETERS')
38
- }
39
-
40
- @test()
41
- protected static canSaveLoggedInPerson() {
42
- const auth = this.auth
43
- const person = {
44
- id: 'test',
45
- casualName: 'friend',
46
- token: 'token',
47
- }
48
-
49
- auth.setLoggedInPerson(person)
50
-
51
- const loggedIn = auth.getLoggedInPerson()
52
-
53
- assert.isEqualDeep(loggedIn, { ...person, isLoggedIn: true })
54
- }
55
-
56
- @test()
57
- protected static canLogOut() {
58
- const auth = this.auth
59
- const person = {
60
- id: 'test',
61
- casualName: 'friend',
62
- token: 'token',
63
- }
64
-
65
- auth.setLoggedInPerson(person)
66
- auth.logOutPerson()
67
-
68
- assert.isNull(auth.getLoggedInPerson())
69
- }
70
-
71
- @test()
72
- protected static getCurrentSkillReturnsNull() {
73
- this.writePackageJson()
74
- assert.isNull(this.auth.getCurrentSkill())
75
- }
76
-
77
- @test()
78
- protected static canSetCurrentSkill() {
79
- this.writePackageJson()
80
- const skill = {
81
- id: '123467aaoeuaoeu',
82
- apiKey: 'taco',
83
- name: 'go team',
84
- slug: 'taco-bravo',
85
- }
86
-
87
- this.auth.updateCurrentSkill(skill)
88
-
89
- assert.isEqualDeep(this.auth.getCurrentSkill(), skill)
90
- }
91
-
92
- private static writePackageJson() {
93
- diskUtil.writeFile(this.resolvePath('package.json'), '{}')
94
- }
95
- }
@@ -1,91 +0,0 @@
1
- import { SpruceSchemas } from '@sprucelabs/mercury-types'
2
- import { normalizeSchemaValues, validateSchemaValues } from '@sprucelabs/schema'
3
- import { EnvService, namesUtil } from '@sprucelabs/spruce-skill-utils'
4
- import personWithTokenSchema from '#spruce/schemas/spruceCli/v2020_07_22/personWithToken.schema'
5
- import PkgService from './PkgService'
6
-
7
- type PersonWithToken = SpruceSchemas.SpruceCli.v2020_07_22.PersonWithToken
8
-
9
- export interface SkillAuth {
10
- id: string
11
- apiKey: string
12
- name: string
13
- slug: string
14
- }
15
-
16
- const LOGGED_IN_PERSON_KEY = 'LOGGED_IN_PERSON'
17
-
18
- export default class AuthService {
19
- private env: EnvService
20
- private pkg: PkgService
21
-
22
- public constructor(envService: EnvService, pkgService: PkgService) {
23
- this.env = envService
24
- this.pkg = pkgService
25
- }
26
-
27
- public getLoggedInPerson(): PersonWithToken | null {
28
- const p = this.env.get(LOGGED_IN_PERSON_KEY)
29
- if (typeof p === 'string') {
30
- return JSON.parse(p)
31
- }
32
-
33
- return null
34
- }
35
-
36
- public setLoggedInPerson(person: PersonWithToken) {
37
- const normalized = normalizeSchemaValues(personWithTokenSchema, person)
38
- validateSchemaValues(personWithTokenSchema, normalized)
39
-
40
- this.env.set(
41
- LOGGED_IN_PERSON_KEY,
42
- JSON.stringify({
43
- ...normalized,
44
- isLoggedIn: true,
45
- })
46
- )
47
- }
48
-
49
- public logOutPerson() {
50
- this.env.unset(LOGGED_IN_PERSON_KEY)
51
- }
52
-
53
- public getCurrentSkill(): SkillAuth | null {
54
- const id = this.env.get('SKILL_ID') as string
55
- const apiKey = this.env.get('SKILL_API_KEY') as string
56
- const name = this.env.get('SKILL_NAME') as string
57
- const slug = this.pkg.get('skill.namespace') as string
58
-
59
- if (id && apiKey) {
60
- return {
61
- id,
62
- apiKey,
63
- name,
64
- slug,
65
- }
66
- }
67
-
68
- return null
69
- }
70
-
71
- public logoutCurrentSkill() {
72
- this.env.unset('SKILL_ID')
73
- this.env.unset('SKILL_API_KEY')
74
- this.env.unset('SKILL_NAME')
75
- }
76
-
77
- public updateCurrentSkill(skill: SkillAuth) {
78
- this.env.set('SKILL_ID', skill.id)
79
- this.env.set('SKILL_API_KEY', skill.apiKey)
80
- this.env.set('SKILL_NAME', skill.name)
81
-
82
- this.updateCurrentSkillNamespace(skill.slug)
83
- }
84
-
85
- public updateCurrentSkillNamespace(namespace: string) {
86
- this.pkg.set({
87
- path: 'skill.namespace',
88
- value: namesUtil.toKebab(namespace),
89
- })
90
- }
91
- }