@sprucelabs/spruce-templates 24.1.32 → 25.0.0

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 (206) hide show
  1. package/build/addons/eq.addon.js.map +1 -0
  2. package/build/addons/escape.addon.js.map +1 -0
  3. package/build/addons/fieldDefinitionBodyPartial.addon.js.map +1 -0
  4. package/build/addons/fieldDefinitionOptions.addon.js.map +1 -0
  5. package/build/addons/fieldTypeEnum.addon.js.map +1 -0
  6. package/build/addons/fieldValue.addon.js.map +1 -0
  7. package/build/addons/gt.addon.js.map +1 -0
  8. package/build/addons/hasKeys.addon.js.map +1 -0
  9. package/build/addons/hasNoneCoreSchemaTemplateItems.addon.js.map +1 -0
  10. package/build/addons/importRelatedSchemas.addon.js.map +1 -0
  11. package/build/addons/index.js.map +1 -0
  12. package/build/addons/isDefined.addon.js.map +1 -0
  13. package/build/addons/json.addon.js.map +1 -0
  14. package/build/addons/neq.addon.js.map +1 -0
  15. package/build/addons/operators.addon.js.map +1 -0
  16. package/build/addons/pascalCase.addon.js.map +1 -0
  17. package/build/addons/permissionContractBuilder.addon.js.map +1 -0
  18. package/build/addons/schemaBodyPartial.addon.js.map +1 -0
  19. package/build/addons/schemaNamespacePath.addon.js.map +1 -0
  20. package/build/addons/schemaValuesPartial.addon.js.map +1 -0
  21. package/build/addons/valueTypeGenerator.addon.js.map +1 -0
  22. package/build/addons/valueTypeLiteral.addon.js.map +1 -0
  23. package/build/addons/valueTypeMapper.addon.js.map +1 -0
  24. package/build/dist/templates/directories/skill/.nvmrc +1 -0
  25. package/build/dist/templates/directories/skill/README.md +4 -0
  26. package/build/dist/templates/directories/skill/eslint.config.mjs +3 -0
  27. package/build/dist/templates/directories/skill/package.json.hbs +15 -0
  28. package/build/dist/templates/directories/skill/src/errors/SpruceError.ts.hbs +20 -0
  29. package/build/dist/templates/directories/skill/tsconfig.json +39 -0
  30. package/build/dist/templates/directories/vscode/.vscode/launch.json +58 -0
  31. package/build/dist/templates/directories/vscode/.vscode/settings.json +67 -0
  32. package/build/dist/templates/directories/vscode/.vscode/tasks.json +112 -0
  33. package/build/dist/templates/typescript/conversation/conversation.plugin.ts.hbs +1 -0
  34. package/build/dist/templates/typescript/conversation/conversation.topic.ts.hbs +19 -0
  35. package/build/dist/templates/typescript/deploy/deploy.plugin.ts.hbs +1 -0
  36. package/build/dist/templates/typescript/error/SpruceError.ts.hbs +31 -0
  37. package/build/dist/templates/typescript/error/error.plugin.ts.hbs +78 -0
  38. package/build/dist/templates/typescript/error/example.ts.hbs +10 -0
  39. package/build/dist/templates/typescript/error/options.types.ts.hbs +12 -0
  40. package/build/dist/templates/typescript/event/event.contract.ts.hbs +26 -0
  41. package/build/dist/templates/typescript/event/event.options.ts.hbs +11 -0
  42. package/build/dist/templates/typescript/event/events.contract.ts.hbs +24 -0
  43. package/build/dist/templates/typescript/event/listener.ts.hbs +23 -0
  44. package/build/dist/templates/typescript/event/listeners.ts.hbs +15 -0
  45. package/build/dist/templates/typescript/event/payload.builder.ts.hbs +15 -0
  46. package/build/dist/templates/typescript/log/transport.plugin.ts.hbs +14 -0
  47. package/build/dist/templates/typescript/permissions/contract.builder.ts.hbs +36 -0
  48. package/build/dist/templates/typescript/permissions/permission.plugin.ts.hbs +1 -0
  49. package/build/dist/templates/typescript/permissions/permissions.ts.hbs +13 -0
  50. package/build/dist/templates/typescript/permissions/permissions.types.ts.hbs +14 -0
  51. package/build/dist/templates/typescript/polish/polish.ts.hbs +67 -0
  52. package/build/dist/templates/typescript/sandbox/will-boot.listener.ts.hbs +172 -0
  53. package/build/dist/templates/typescript/schema/builder.ts.hbs +24 -0
  54. package/build/dist/templates/typescript/schema/core.schemas.types.ts.hbs +34 -0
  55. package/build/dist/templates/typescript/schema/example.ts.hbs +20 -0
  56. package/build/dist/templates/typescript/schema/fields/fieldClassMap.ts.hbs +16 -0
  57. package/build/dist/templates/typescript/schema/fields/fields.types.ts.hbs +1 -0
  58. package/build/dist/templates/typescript/schema/imported.schema.ts.hbs +1 -0
  59. package/build/dist/templates/typescript/schema/partials/fieldDefinitionBody.ts.hbs +12 -0
  60. package/build/dist/templates/typescript/schema/partials/schemaBody.ts.hbs +20 -0
  61. package/build/dist/templates/typescript/schema/partials/schemaValues.ts.hbs +7 -0
  62. package/build/dist/templates/typescript/schema/schema.plugin.ts.hbs +101 -0
  63. package/build/dist/templates/typescript/schema/schema.ts.hbs +12 -0
  64. package/build/dist/templates/typescript/schema/schemas.types.ts.hbs +44 -0
  65. package/build/dist/templates/typescript/schema/valueTypes.ts.hbs +67 -0
  66. package/build/dist/templates/typescript/store/Store.store.ts.hbs +95 -0
  67. package/build/dist/templates/typescript/store/store.plugin.ts.hbs +1 -0
  68. package/build/dist/templates/typescript/store/stores.ts.hbs +9 -0
  69. package/build/dist/templates/typescript/store/stores.types.ts.hbs +17 -0
  70. package/build/dist/templates/typescript/test/StaticTest.test.ts.hbs +20 -0
  71. package/build/dist/templates/typescript/test/Test.test.ts.hbs +21 -0
  72. package/build/dist/templates/typescript/view/App.ac.ts.hbs +6 -0
  73. package/build/dist/templates/typescript/view/View.svc.ts.hbs +23 -0
  74. package/build/dist/templates/typescript/view/View.vc.ts.hbs +17 -0
  75. package/build/dist/templates/typescript/view/skill.theme.ts.hbs +70 -0
  76. package/build/dist/templates/typescript/view/view.plugin.ts.hbs +1 -0
  77. package/build/dist/templates/typescript/view/viewController.plugin.ts.hbs +3 -0
  78. package/build/dist/templates/typescript/view/views.ts.hbs +93 -0
  79. package/build/esm/addons/eq.addon.d.ts +1 -0
  80. package/build/esm/addons/eq.addon.js +4 -0
  81. package/build/esm/addons/escape.addon.d.ts +1 -0
  82. package/build/esm/addons/escape.addon.js +5 -0
  83. package/build/esm/addons/fieldDefinitionBodyPartial.addon.d.ts +1 -0
  84. package/build/esm/addons/fieldDefinitionBodyPartial.addon.js +8 -0
  85. package/build/esm/addons/fieldDefinitionOptions.addon.d.ts +1 -0
  86. package/build/esm/addons/fieldDefinitionOptions.addon.js +66 -0
  87. package/build/esm/addons/fieldTypeEnum.addon.d.ts +1 -0
  88. package/build/esm/addons/fieldTypeEnum.addon.js +9 -0
  89. package/build/esm/addons/fieldValue.addon.d.ts +1 -0
  90. package/build/esm/addons/fieldValue.addon.js +8 -0
  91. package/build/esm/addons/gt.addon.d.ts +1 -0
  92. package/build/esm/addons/gt.addon.js +4 -0
  93. package/build/esm/addons/hasKeys.addon.d.ts +1 -0
  94. package/build/esm/addons/hasKeys.addon.js +4 -0
  95. package/build/esm/addons/hasNoneCoreSchemaTemplateItems.addon.d.ts +1 -0
  96. package/build/esm/addons/hasNoneCoreSchemaTemplateItems.addon.js +6 -0
  97. package/build/esm/addons/importRelatedSchemas.addon.d.ts +1 -0
  98. package/build/esm/addons/importRelatedSchemas.addon.js +34 -0
  99. package/build/esm/addons/index.d.ts +23 -0
  100. package/build/esm/addons/index.js +23 -0
  101. package/build/esm/addons/isDefined.addon.d.ts +1 -0
  102. package/build/esm/addons/isDefined.addon.js +5 -0
  103. package/build/esm/addons/json.addon.d.ts +1 -0
  104. package/build/esm/addons/json.addon.js +7 -0
  105. package/build/esm/addons/neq.addon.d.ts +1 -0
  106. package/build/esm/addons/neq.addon.js +4 -0
  107. package/build/esm/addons/operators.addon.d.ts +1 -0
  108. package/build/esm/addons/operators.addon.js +15 -0
  109. package/build/esm/addons/pascalCase.addon.d.ts +1 -0
  110. package/build/esm/addons/pascalCase.addon.js +6 -0
  111. package/build/esm/addons/permissionContractBuilder.addon.d.ts +1 -0
  112. package/build/esm/addons/permissionContractBuilder.addon.js +4 -0
  113. package/build/esm/addons/schemaBodyPartial.addon.d.ts +1 -0
  114. package/build/esm/addons/schemaBodyPartial.addon.js +8 -0
  115. package/build/esm/addons/schemaNamespacePath.addon.d.ts +1 -0
  116. package/build/esm/addons/schemaNamespacePath.addon.js +18 -0
  117. package/build/esm/addons/schemaValuesPartial.addon.d.ts +1 -0
  118. package/build/esm/addons/schemaValuesPartial.addon.js +8 -0
  119. package/build/esm/addons/valueTypeGenerator.addon.d.ts +1 -0
  120. package/build/esm/addons/valueTypeGenerator.addon.js +15 -0
  121. package/build/esm/addons/valueTypeLiteral.addon.d.ts +1 -0
  122. package/build/esm/addons/valueTypeLiteral.addon.js +32 -0
  123. package/build/esm/addons/valueTypeMapper.addon.d.ts +1 -0
  124. package/build/esm/addons/valueTypeMapper.addon.js +9 -0
  125. package/build/esm/index.d.ts +141 -0
  126. package/build/esm/index.js +258 -0
  127. package/build/esm/templates/directories/skill/.nvmrc +1 -0
  128. package/build/esm/templates/directories/skill/README.md +4 -0
  129. package/build/esm/templates/directories/skill/eslint.config.mjs +3 -0
  130. package/build/esm/templates/directories/skill/package.json.hbs +15 -0
  131. package/build/esm/templates/directories/skill/src/.spruce/errors/options.types.ts +6 -0
  132. package/build/esm/templates/directories/skill/src/.spruce/features/event.plugin.ts +1 -0
  133. package/build/esm/templates/directories/skill/src/.spruce/skill.ts +8 -0
  134. package/build/esm/templates/directories/skill/src/errors/SpruceError.ts.hbs +20 -0
  135. package/build/esm/templates/directories/skill/src/index.ts +35 -0
  136. package/build/esm/templates/directories/skill/tsconfig.json +39 -0
  137. package/build/esm/templates/directories/vscode/.vscode/launch.json +58 -0
  138. package/build/esm/templates/directories/vscode/.vscode/settings.json +67 -0
  139. package/build/esm/templates/directories/vscode/.vscode/tasks.json +112 -0
  140. package/build/esm/templates/typescript/conversation/conversation.plugin.ts.hbs +1 -0
  141. package/build/esm/templates/typescript/conversation/conversation.topic.ts.hbs +19 -0
  142. package/build/esm/templates/typescript/deploy/deploy.plugin.ts.hbs +1 -0
  143. package/build/esm/templates/typescript/error/SpruceError.ts.hbs +31 -0
  144. package/build/esm/templates/typescript/error/error.plugin.ts.hbs +78 -0
  145. package/build/esm/templates/typescript/error/example.ts.hbs +10 -0
  146. package/build/esm/templates/typescript/error/options.types.ts.hbs +12 -0
  147. package/build/esm/templates/typescript/event/event.contract.ts.hbs +26 -0
  148. package/build/esm/templates/typescript/event/event.options.ts.hbs +11 -0
  149. package/build/esm/templates/typescript/event/events.contract.ts.hbs +24 -0
  150. package/build/esm/templates/typescript/event/listener.ts.hbs +23 -0
  151. package/build/esm/templates/typescript/event/listeners.ts.hbs +15 -0
  152. package/build/esm/templates/typescript/event/payload.builder.ts.hbs +15 -0
  153. package/build/esm/templates/typescript/log/transport.plugin.ts.hbs +14 -0
  154. package/build/esm/templates/typescript/permissions/contract.builder.ts.hbs +36 -0
  155. package/build/esm/templates/typescript/permissions/permission.plugin.ts.hbs +1 -0
  156. package/build/esm/templates/typescript/permissions/permissions.ts.hbs +13 -0
  157. package/build/esm/templates/typescript/permissions/permissions.types.ts.hbs +14 -0
  158. package/build/esm/templates/typescript/polish/polish.ts.hbs +67 -0
  159. package/build/esm/templates/typescript/sandbox/will-boot.listener.ts.hbs +172 -0
  160. package/build/esm/templates/typescript/schema/builder.ts.hbs +24 -0
  161. package/build/esm/templates/typescript/schema/core.schemas.types.ts.hbs +34 -0
  162. package/build/esm/templates/typescript/schema/example.ts.hbs +20 -0
  163. package/build/esm/templates/typescript/schema/fields/fieldClassMap.ts.hbs +16 -0
  164. package/build/esm/templates/typescript/schema/fields/fields.types.ts.hbs +1 -0
  165. package/build/esm/templates/typescript/schema/imported.schema.ts.hbs +1 -0
  166. package/build/esm/templates/typescript/schema/partials/fieldDefinitionBody.ts.hbs +12 -0
  167. package/build/esm/templates/typescript/schema/partials/schemaBody.ts.hbs +20 -0
  168. package/build/esm/templates/typescript/schema/partials/schemaValues.ts.hbs +7 -0
  169. package/build/esm/templates/typescript/schema/schema.plugin.ts.hbs +101 -0
  170. package/build/esm/templates/typescript/schema/schema.ts.hbs +12 -0
  171. package/build/esm/templates/typescript/schema/schemas.types.ts.hbs +44 -0
  172. package/build/esm/templates/typescript/schema/valueTypes.ts.hbs +67 -0
  173. package/build/esm/templates/typescript/store/Store.store.ts.hbs +95 -0
  174. package/build/esm/templates/typescript/store/store.plugin.ts.hbs +1 -0
  175. package/build/esm/templates/typescript/store/stores.ts.hbs +9 -0
  176. package/build/esm/templates/typescript/store/stores.types.ts.hbs +17 -0
  177. package/build/esm/templates/typescript/test/StaticTest.test.ts.hbs +20 -0
  178. package/build/esm/templates/typescript/test/Test.test.ts.hbs +21 -0
  179. package/build/esm/templates/typescript/view/App.ac.ts.hbs +6 -0
  180. package/build/esm/templates/typescript/view/View.svc.ts.hbs +23 -0
  181. package/build/esm/templates/typescript/view/View.vc.ts.hbs +17 -0
  182. package/build/esm/templates/typescript/view/skill.theme.ts.hbs +70 -0
  183. package/build/esm/templates/typescript/view/view.plugin.ts.hbs +1 -0
  184. package/build/esm/templates/typescript/view/viewController.plugin.ts.hbs +3 -0
  185. package/build/esm/templates/typescript/view/views.ts.hbs +93 -0
  186. package/build/esm/types/templates.types.d.ts +122 -0
  187. package/build/esm/types/templates.types.js +5 -0
  188. package/build/esm/utilities/DirectoryTemplateUtility.d.ts +15 -0
  189. package/build/esm/utilities/DirectoryTemplateUtility.js +79 -0
  190. package/build/esm/utilities/KeyGeneratorUtility.d.ts +5 -0
  191. package/build/esm/utilities/KeyGeneratorUtility.js +6 -0
  192. package/build/esm/utilities/importExtractor.utility.d.ts +10 -0
  193. package/build/esm/utilities/importExtractor.utility.js +32 -0
  194. package/build/esm/utilities/templateImporter.utility.d.ts +4 -0
  195. package/build/esm/utilities/templateImporter.utility.js +18 -0
  196. package/build/esm/utilities/templateItem.utility.d.ts +6 -0
  197. package/build/esm/utilities/templateItem.utility.js +25 -0
  198. package/build/index.js.map +1 -0
  199. package/build/types/templates.types.js.map +1 -0
  200. package/build/utilities/DirectoryTemplateUtility.js.map +1 -0
  201. package/build/utilities/KeyGeneratorUtility.js.map +1 -0
  202. package/build/utilities/importExtractor.utility.js.map +1 -0
  203. package/build/utilities/templateImporter.utility.js.map +1 -0
  204. package/build/utilities/templateItem.utility.js.map +1 -0
  205. package/package.json +7 -7
  206. package/LICENSE +0 -21
@@ -0,0 +1,24 @@
1
+ {{#if shouldImportCoreEvents}}import { coreEventContracts } from '@sprucelabs/mercury-core-events'{{/if}}
2
+
3
+ {{#each contracts}}
4
+ import {{namespaceCamel}}{{namePascal}}EventContract_{{version}}, { {{namePascal}}EventContract as {{namespacePascal}}{{namePascal}}EventContract_{{version}} } from '#spruce/events/{{ namespaceCamel }}/{{ nameCamel }}.{{ version }}.contract'
5
+ {{/each}}
6
+
7
+ export default [
8
+ {{#each contracts}}
9
+ {{namespaceCamel}}{{namePascal}}EventContract_{{version}},
10
+ {{/each}}
11
+ {{#if shouldImportCoreEvents}}...coreEventContracts,{{/if}}
12
+ ]
13
+
14
+ declare module '{{skillEventContractTypesFile}}' {
15
+ interface SkillEventSignatures {
16
+ {{#each contracts}}
17
+
18
+ {{#each eventSignatures}}
19
+ '{{@key}}': {{../namespacePascal}}{{../namePascal}}EventContract_{{../version}}['eventSignatures']['{{@key}}'],
20
+ {{/each}}
21
+
22
+ {{/each}}
23
+ }
24
+ }
@@ -0,0 +1,23 @@
1
+ import SpruceError from '#spruce/../errors/SpruceError'
2
+ import { SpruceEvent, SpruceEventResponse } from '@sprucelabs/spruce-event-utils'
3
+ {{#if emitPayloadSchemaTemplateItem}}import { SkillEventContract } from '@sprucelabs/mercury-types'{{/if}}
4
+ {{#if shouldImportGlobalSchema}}import { {{globalSchemaNamespace}} } from '{{schemaTypesFile}}'{{/if}}
5
+
6
+ export default async (event: SpruceEvent{{#if emitPayloadSchemaTemplateItem}}<SkillEventContract, EmitPayload>{{/if}}): SpruceEventResponse{{#if responsePayloadSchemaTemplateItem}}<ResponsePayload>{{/if}} => {
7
+ console.log(event)
8
+
9
+ throw new SpruceError({
10
+ //@ts-ignore
11
+ code: 'LISTENER_NOT_IMPLEMENTED',
12
+ //@ts-ignore
13
+ fullyQualifiedEventName: '{{fullyQualifiedEventName}}'
14
+ })
15
+
16
+ //return {}
17
+ }
18
+
19
+ {{#if emitPayloadSchemaTemplateItem}}
20
+ type EmitPayload = {{{ schemaNamespacePath schemaTemplateItem=emitPayloadSchemaTemplateItem }}}
21
+ {{/if}}{{#if responsePayloadSchemaTemplateItem}}
22
+ type ResponsePayload = {{{ schemaNamespacePath schemaTemplateItem=responsePayloadSchemaTemplateItem }}}
23
+ {{/if}}
@@ -0,0 +1,15 @@
1
+ import { EventFeatureListener } from '@sprucelabs/spruce-event-utils'
2
+
3
+ const listeners: EventFeatureListener[] = [
4
+ {{#each listeners}}
5
+ {
6
+ eventName: '{{eventName}}',
7
+ eventNamespace: '{{eventNamespace}}',
8
+ version: '{{version}}',
9
+ callback: require('{{path}}').default,
10
+ isGlobal: require('{{path}}').isGlobal,
11
+ },
12
+ {{/each}}
13
+ ]
14
+
15
+ export default listeners
@@ -0,0 +1,15 @@
1
+ import {
2
+ buildSchema
3
+ } from '@sprucelabs/schema'
4
+
5
+ const {{nameCamel}}{{actionCamel}}Builder = buildSchema({
6
+ id: '{{nameCamel}}{{actionCamel}}',
7
+ fields: {
8
+ aTextField: {
9
+ type: 'text',
10
+ label: 'Update me',
11
+ }
12
+ }
13
+ })
14
+
15
+ export default {{nameCamel}}{{actionCamel}}Builder
@@ -0,0 +1,14 @@
1
+ import { Level, LogTransport } from '@sprucelabs/spruce-skill-utils'
2
+
3
+ export default function (): {
4
+ levels: Level[]
5
+ transport: LogTransport
6
+ } | null {
7
+ return {
8
+ levels: [],
9
+ transport: (...messageParts: string[]) => {
10
+ const message = messageParts.join(' ')
11
+ console.log(message)
12
+ },
13
+ }
14
+ }
@@ -0,0 +1,36 @@
1
+ import {
2
+ buildPermissionContract
3
+ } from '@sprucelabs/mercury-types'
4
+
5
+ const {{ nameCamel }}Permissions = buildPermissionContract({
6
+ id: '{{nameKebab}}',
7
+ name: '{{{escape nameReadable}}}',
8
+ description: '{{{escape description}}}',
9
+ requireAllPermissions: false,
10
+ permissions: [
11
+ {
12
+ id: 'can-high-five',
13
+ name: 'Can give high five',
14
+ description: 'Will this person be allowed to high five?',
15
+
16
+ defaults: {
17
+ /**
18
+ Uncomment this comment to set which roles will pass by default. Keep
19
+ in mind this is overridden by the people who install your skill.
20
+
21
+ guest: { onPrem: true },
22
+ owner: { onPrem: true },
23
+ groupManager: { onPrem: true },
24
+ manager: { onPrem: true },
25
+ teammate: { onPrem: true },
26
+ anonymous: { default: false },
27
+
28
+ **/
29
+ skill: false,
30
+ },
31
+ requireAllStatuses: false,
32
+ }
33
+ ]
34
+ })
35
+
36
+ export default {{ nameCamel }}Permissions
@@ -0,0 +1 @@
1
+ export { plugin as default } from '@sprucelabs/spruce-permission-plugin'
@@ -0,0 +1,13 @@
1
+ import { PermissionContract } from "@sprucelabs/mercury-types"
2
+ {{#each contracts}}
3
+ import {{nameCamel}}PermissionContract from '{{path}}'
4
+ {{/each}}
5
+
6
+ const contracts: PermissionContract[] = [
7
+ {{#each contracts}}
8
+ {{nameCamel}}PermissionContract,
9
+ {{/each}}
10
+ ]
11
+
12
+
13
+ export default contracts
@@ -0,0 +1,14 @@
1
+ import '@sprucelabs/mercury-types'
2
+
3
+ declare module '@sprucelabs/mercury-types/build/types/mercury.types' {
4
+ interface PermissionContractMap {
5
+ {{#each contracts}}
6
+ '{{@key}}': [
7
+ {{#each this}}'{{this}}',{{/each}}
8
+ ]
9
+ {{/each}}
10
+ }
11
+ }
12
+
13
+
14
+ export interface PermissionContractMap {}
@@ -0,0 +1,67 @@
1
+ import { PolishStep } from '@sprucelabs/heartwood-polish'
2
+
3
+ // Documentation: https://developer.spruce.ai/#/polish/index
4
+
5
+ const script: PolishStep[] = [
6
+ /**{
7
+ redirect: {
8
+ id: 'heartwood.root',
9
+ },
10
+ },
11
+ {
12
+ typeText: {
13
+ target: [['Field', 'phone']],
14
+ text: '5555555555',
15
+ },
16
+ },
17
+ {
18
+ assert: {
19
+ target: [['Field', 'phone']],
20
+ inputValue: {
21
+ equals: '+1 555-555-5555',
22
+ },
23
+ },
24
+ },
25
+ {
26
+ click: {
27
+ target: [['Button', 'primary']],
28
+ },
29
+ },
30
+ {
31
+ typeText: {
32
+ target: [['Field', 'code']],
33
+ text: '5555',
34
+ },
35
+ },
36
+ {
37
+ click: {
38
+ target: [['NavMenu', 'settings']],
39
+ },
40
+ },
41
+ {
42
+ click: {
43
+ target: [['NavLink', 'logout']],
44
+ },
45
+ },
46
+ {
47
+ click: {
48
+ target: [['Dialog', 'primary']],
49
+ },
50
+ },
51
+ {
52
+ typeText: {
53
+ target: [['Field', 'phone']],
54
+ text: '555-555-2323',
55
+ },
56
+ },
57
+ {
58
+ assert: {
59
+ target: [['Field', 'phone']],
60
+ inputValue: {
61
+ equals: '+1 555-555-2323',
62
+ },
63
+ },
64
+ },**/
65
+ ]
66
+
67
+ export default script
@@ -0,0 +1,172 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client'
2
+ import { SchemaError } from '@sprucelabs/schema'
3
+ import { EventFeature } from '@sprucelabs/spruce-event-plugin'
4
+ import {
5
+ SpruceEvent,
6
+ SpruceEventResponse,
7
+ eventResponseUtil,
8
+ } from '@sprucelabs/spruce-event-utils'
9
+ import { EnvService, PkgService } from '@sprucelabs/spruce-skill-utils'
10
+
11
+ export default async (event: SpruceEvent): SpruceEventResponse => {
12
+ const sandboxNumber = process.env.SANDBOX_DEMO_NUMBER
13
+
14
+ if (sandboxNumber && process.env.SKILL_ID) {
15
+ const log = event.log.buildLog('Sandbox')
16
+
17
+ log.info('Demo sandbox number detected. Checking skill status.')
18
+
19
+ const events = event.skill.getFeatureByCode('event') as EventFeature
20
+
21
+ const env = new EnvService(event.skill.rootDir)
22
+ const pkg = new PkgService(event.skill.rootDir)
23
+
24
+ process.env.SKILL_ID = (env.get('SKILL_ID') ??
25
+ process.env.SKILL_ID) as string
26
+ process.env.SKILL_API_KEY = (env.get('SKILL_API_KEY') ??
27
+ process.env.SKILL_API_KEY) as string
28
+
29
+ try {
30
+ await events.connectToApi({ shouldWaitForWillBoot: false })
31
+ return
32
+ } catch {}
33
+
34
+ log.warn('It looks like sandbox was reset. Re-registering.')
35
+
36
+ const name = process.env.SKILL_NAME as string
37
+ const slug = pkg.get(['skill', 'namespace']) as string
38
+
39
+ assertRequiredParams(name, slug)
40
+
41
+ delete process.env.SKILL_ID
42
+ delete process.env.SKILL_API_KEY
43
+
44
+ const client = (await events.connectToApi({
45
+ shouldWaitForWillBoot: false,
46
+ })) as any
47
+
48
+ await login(client, sandboxNumber)
49
+
50
+ const skill = await registerOrLoginSkill(client, name, slug)
51
+ await client.emit(`logout::v2020_12_25`)
52
+
53
+ await client.authenticate({
54
+ skillId: skill.id,
55
+ apiKey: skill.apiKey,
56
+ })
57
+
58
+ env.set('SKILL_ID', skill.id)
59
+ env.set('SKILL_API_KEY', skill.apiKey)
60
+ }
61
+
62
+ return
63
+ }
64
+
65
+ async function login(client: any, sandboxNumber: string) {
66
+ const requestResults = await client.emit('request-pin::v2020_12_25', {
67
+ payload: {
68
+ phone: sandboxNumber,
69
+ },
70
+ })
71
+
72
+ const { challenge } =
73
+ eventResponseUtil.getFirstResponseOrThrow(requestResults)
74
+
75
+ const confirmResults = await client.emit('confirm-pin::v2020_12_25', {
76
+ payload: {
77
+ challenge,
78
+ pin: sandboxNumber.substr(-4),
79
+ },
80
+ })
81
+
82
+ eventResponseUtil.getFirstResponseOrThrow(confirmResults)
83
+ }
84
+
85
+ function assertRequiredParams(
86
+ name: string | undefined,
87
+ slug: string | undefined
88
+ ) {
89
+ const missing: string[] = []
90
+
91
+ if (!name) {
92
+ missing.push('env.SKILL_NAME')
93
+ }
94
+
95
+ if (!slug) {
96
+ missing.push('env.SKILL_SLUG')
97
+ }
98
+
99
+ if (missing.length > 0) {
100
+ throw new SchemaError({
101
+ code: 'MISSING_PARAMETERS',
102
+ parameters: missing,
103
+ })
104
+ }
105
+ }
106
+
107
+ async function registerOrLoginSkill(
108
+ client: MercuryClient,
109
+ name: string,
110
+ slug: string
111
+ ) {
112
+ let skill: any
113
+ try {
114
+ skill = await registerSkill(client, name, slug)
115
+ } catch (err: any) {
116
+ skill = await loginSkill(client, slug)
117
+ }
118
+ process.env.SKILL_ID = skill.id
119
+ process.env.SKILL_API_KEY = skill.apiKey
120
+
121
+ return skill
122
+ }
123
+
124
+ async function registerSkill(
125
+ client: MercuryClient,
126
+ name: string,
127
+ slug: string
128
+ ) {
129
+ const [{ skill }] = await client.emitAndFlattenResponses(
130
+ 'register-skill::v2020_12_25',
131
+ {
132
+ payload: {
133
+ name,
134
+ description: 'Auto-generate for sandbox',
135
+ slug,
136
+ },
137
+ }
138
+ )
139
+
140
+ return skill
141
+ }
142
+
143
+ async function loginSkill(client: MercuryClient, slug: string) {
144
+ const [{ skills }] = await client.emitAndFlattenResponses(
145
+ 'list-skills::v2020_12_25',
146
+ {
147
+ payload: {
148
+ shouldOnlyShowMine: true,
149
+ },
150
+ }
151
+ )
152
+
153
+ const match = skills.find((s: any) => s.slug === slug)
154
+
155
+ if (!match) {
156
+ throw new Error(`Could not find skill with slug ${slug}`)
157
+ }
158
+
159
+ const [{ skill }] = await client.emitAndFlattenResponses(
160
+ 'get-skill::v2020_12_25',
161
+ {
162
+ target: {
163
+ skillId: match.id,
164
+ },
165
+ payload: {
166
+ shouldIncludeApiKey: true,
167
+ },
168
+ }
169
+ )
170
+
171
+ return skill
172
+ }
@@ -0,0 +1,24 @@
1
+ import { {{builderFunction}} } from '@sprucelabs/schema'
2
+
3
+
4
+ export default {{builderFunction}}({
5
+ id: '{{nameCamel}}',
6
+ name: '{{{escape nameReadable}}}',{{#if description}}
7
+ description: '{{{escape description}}}',{{/if}}{{#if moduleToImportFromWhenRemote}}
8
+ moduleToImportFromWhenRemote: '{{{escape moduleToImportFromWhenRemote}}}',{{/if}}
9
+ fields: {
10
+ fieldName1: {
11
+ type: 'text',
12
+ label: 'First Field',
13
+ isRequired: true
14
+ },
15
+ fieldName2: {
16
+ type: 'number',
17
+ label: 'Second Field',
18
+ isRequired: true,
19
+ hint:
20
+ 'A hint'
21
+ }
22
+ }
23
+ })
24
+
@@ -0,0 +1,34 @@
1
+ import { default as SchemaEntity } from '@sprucelabs/schema'
2
+ {{#each imports}}
3
+ import * as {{importAs}} from '{{package}}'
4
+ {{/each}}
5
+ {{#each schemaTemplateItems}}
6
+
7
+ {{#each imports}}
8
+ {{{this}}}
9
+ {{/each}}
10
+ {{/each}}
11
+
12
+
13
+
14
+ {{#each schemaTemplateItems}}
15
+
16
+ export declare namespace {{../globalSchemaNamespace}}.{{namespace}}{{#if (isDefined schema.version)}}.{{schema.version}}{{/if}} {
17
+
18
+ {{#if schema.description}}/** {{schema.description}} */{{/if}}
19
+ export interface {{namePascal}} {
20
+ {{> schemaValues schema=schema renderAs="type" }}
21
+ }
22
+
23
+ export interface {{namePascal}}Schema extends SpruceSchema.Schema {
24
+ {{> schemaBody namespace=namespace schema=schema renderAs="type" }}
25
+ }
26
+
27
+ export type {{namePascal}}Entity = SchemaEntity<{{../globalSchemaNamespace}}.{{namespace}}{{#if (isDefined schema.version)}}.{{schema.version}}{{/if}}.{{namePascal}}Schema>
28
+
29
+ }
30
+
31
+ {{/each}}
32
+
33
+
34
+
@@ -0,0 +1,20 @@
1
+ // Importing your schema
2
+ import {{nameCamel}}Schema from '#spruce/schemas/v2020_07_22/{{nameCamel}}.schema'
3
+
4
+ // Importing interfaces
5
+ import { {{namePascal}}, {{namePascal}}Entity } from '#spruce/schemas/v2020_07_22/{{nameCamel}}.types'
6
+
7
+ // Create an entity instance based on a schema
8
+ import Entity from '@sprucelabs/schema'
9
+ const {{nameCamel}} = new Entity({{nameCamel}}Schema, values)
10
+
11
+ // Set a value
12
+ {{nameCamel}}.set('fieldName', newValue);
13
+
14
+ // Get some values
15
+ {{#each schema.fields}}
16
+ const {{@key}} = {{../nameCamel}}.get('{{@key}}');
17
+ {{/each}}
18
+
19
+ // ensure it validates
20
+ {{nameCamel}}.validate() // throws SchemaFieldValidationError
@@ -0,0 +1,16 @@
1
+ import { fieldClassMap } from '@sprucelabs/schema'
2
+
3
+ {{#each fieldTemplateItems}}
4
+ {{#if isLocal}}
5
+ import {{className}} from '{{package}}'
6
+ {{/if}}
7
+ {{/each}}
8
+
9
+
10
+ {{#each fieldTemplateItems}}
11
+ {{#if isLocal}}
12
+ fieldClassMap.{{camelType}} = {{className}}
13
+ {{/if}}
14
+ {{/each}}
15
+
16
+ export default fieldClassMap
@@ -0,0 +1 @@
1
+ export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema'
@@ -0,0 +1 @@
1
+ export { {{nameCamel}}Schema as default } from '{{importFrom}}'
@@ -0,0 +1,12 @@
1
+ {{#if field.label}}label: '{{{escape field.label}}}',
2
+ {{/if}}type: {{{fieldTypeEnum field}}}{{#if field.keyName}},
3
+ keyName: '{{{escape field.keyName}}}'{{/if}}{{#if field.isPrivate}},
4
+ isPrivate: true{{/if}}{{#if field.isRequired}},
5
+ isRequired: true{{/if}}{{#if field.hint}},
6
+ hint: '{{{escape field.hint}}}'{{/if}}{{#if (isDefined field.value)}},
7
+ value: {{{json field.value}}}{{/if}}{{#if (isDefined field.defaultValue)}},
8
+ defaultValue: {{{json field.defaultValue}}}{{/if}}{{#if field.isArray}},
9
+ isArray: true{{/if}}{{#if (isDefined field.minArrayLength)}},
10
+ minArrayLength: {{field.minArrayLength}}{{/if}}{{#if field.description}},
11
+ description: '{{{escape field.description}}}'{{/if}},
12
+ options: {{{fieldDefinitionOptions namespace schemaNameCamel schema.version fieldName field renderAs}}}
@@ -0,0 +1,20 @@
1
+ id: '{{{escape schema.id}}}',{{#if schema.version}}
2
+ version: '{{{escape schema.version}}}',{{/if}}{{#if namespace}}
3
+ namespace: '{{{escape namespace}}}',{{/if}}
4
+ name: '{{{escape schema.name}}}',{{#if schema.importsWhenRemote}}
5
+ importsWhenRemote: [{{#each schema.importsWhenRemote}}'{{{escape this}}}',{{/each}}],{{/if}}{{#if schema.moduleToImportFromWhenRemote}}
6
+ moduleToImportFromWhenRemote: '{{{escape schema.moduleToImportFromWhenRemote}}}',{{/if}}{{#if schema.description}}
7
+ description: '{{{escape schema.description}}}',{{/if}}{{#if schema.typeSuffix}}
8
+ typeSuffix: '{{{escape schema.typeSuffix}}}',{{/if}}{{#if schema.dynamicFieldSignature}}
9
+ dynamicFieldSignature: {
10
+ {{> fieldDefinitionBody namespace=namespace schemaNameCamel=nameCamel schema=schema fieldName="__dynamicFieldSignature" field=schema.dynamicFieldSignature renderAs=renderAs}}
11
+ },{{/if}}{{#if schema.fields}}
12
+ fields: {
13
+ {{#each schema.fields}}
14
+ /** {{{label}}}.{{#if hint}} {{{hint}}}{{/if}} */
15
+ '{{@key}}': {
16
+ {{> fieldDefinitionBody namespace=../namespace schemaNameCamel=../nameCamel schema=../schema fieldName=@key field=this renderAs=../renderAs }}
17
+ },
18
+ {{/each}}
19
+ }
20
+ {{/if}}
@@ -0,0 +1,7 @@
1
+ {{#if schema.dynamicFieldSignature }}
2
+ /** {{schema.dynamicFieldSignature.label}}.{{#if schema.dynamicFieldSignature.hint}} {{schema.dynamicFieldSignature.hint}}{{/if}} */
3
+ [{{schema.dynamicFieldSignature.keyName}}:string]: {{{valueTypeLiteral namespace nameCamel schema.version "__dynamicFieldSignature" renderAs }}}{{#unless schema.dynamicFieldSignature.isRequired}}| undefined | null{{/unless}}{{/if}}
4
+ {{#each schema.fields}}
5
+ {{#if (or label hint) }}/** {{{label}}}.{{#if hint}} {{{hint}}}{{/if}} */{{/if}}
6
+ '{{@key}}'{{#unless isRequired}}?{{/unless}}: {{{valueTypeLiteral ../namespace ../nameCamel ../schema.version @key ../renderAs }}}{{#unless isRequired}} | undefined | null{{/unless}}
7
+ {{/each}}
@@ -0,0 +1,101 @@
1
+ import fs from 'fs'
2
+ import pathUtil from 'path'
3
+ import globby from '@sprucelabs/globby'
4
+ import { SchemaError } from '@sprucelabs/schema'
5
+ import {
6
+ SchemaHealthCheckItem,
7
+ SkillFeature,
8
+ Skill,
9
+ diskUtil,
10
+ HASH_SPRUCE_DIR_NAME,
11
+ BootCallback,
12
+ } from '@sprucelabs/spruce-skill-utils'
13
+
14
+ class SchemaFeature implements SkillFeature {
15
+ private skill: Skill
16
+ private _isBooted = false
17
+ private bootHandler?: BootCallback
18
+
19
+ public constructor(skill: Skill) {
20
+ this.skill = skill
21
+ }
22
+
23
+ public onBoot(cb: BootCallback) {
24
+ this.bootHandler = cb
25
+ }
26
+
27
+ public execute = async () => {
28
+ if (process.env.SHOULD_VALIDATE_SCHEMAS_ON_BOOT !== 'false') {
29
+ await this.loadSchemas()
30
+ }
31
+ this._isBooted = true
32
+ void this.bootHandler?.()
33
+ }
34
+
35
+ public checkHealth = async () => {
36
+ const schemas = await this.loadSchemas()
37
+
38
+ const health: SchemaHealthCheckItem = {
39
+ status: 'passed',
40
+ schemas,
41
+ }
42
+
43
+ return health
44
+ }
45
+
46
+ public async destroy() {
47
+ this._isBooted = false
48
+ }
49
+
50
+ public isInstalled = async () => {
51
+ const schemaPath = pathUtil.join(
52
+ this.skill.rootDir,
53
+ 'node_modules',
54
+ '@sprucelabs/schema'
55
+ )
56
+
57
+ const isSchemaInstalled = fs.existsSync(schemaPath)
58
+
59
+ return isSchemaInstalled
60
+ }
61
+
62
+ public isBooted() {
63
+ return this._isBooted
64
+ }
65
+
66
+ private async loadSchemas() {
67
+ const schemaFiles = await globby(
68
+ diskUtil.resolvePath(
69
+ this.skill.activeDir,
70
+ HASH_SPRUCE_DIR_NAME,
71
+ 'schemas',
72
+ '**/*.schema.[t|j]s'
73
+ )
74
+ )
75
+
76
+ return schemaFiles.map((file) => {
77
+ try {
78
+ const schema = require(file).default
79
+ return {
80
+ id: schema.id,
81
+ name: schema.name,
82
+ version: schema.version,
83
+ namespace: schema.namespace ?? '***MISSING***',
84
+ description: schema.description,
85
+ }
86
+ } catch (err: any) {
87
+ throw new SchemaError({
88
+ //@ts-ignore
89
+ code: 'FAILED_LOADING_SCHEMA',
90
+ originalError: err,
91
+ friendlyMessage: `Error importing schema from: ${file}.`,
92
+ })
93
+ }
94
+ })
95
+ }
96
+ }
97
+
98
+ export default (skill: Skill) => {
99
+ const feature = new SchemaFeature(skill)
100
+ skill.registerFeature('schema', feature)
101
+ }
@@ -0,0 +1,12 @@
1
+ {{#if registerBuiltSchemas}}import { SchemaRegistry } from '@sprucelabs/schema'{{/if}}
2
+ import { {{globalSchemaNamespace}} } from '{{typesFile}}'
3
+
4
+ {{{ importRelatedSchemas schema }}}
5
+
6
+ const {{nameCamel}}Schema: {{globalSchemaNamespace}}.{{namespace}}{{#if schema.version}}.{{schema.version}}{{/if}}.{{namePascal}}Schema = {
7
+ {{> schemaBody nameCamel=nameCamel namespace=namespace schema=schema renderAs="value" }}
8
+ }
9
+
10
+ {{#if registerBuiltSchemas}}SchemaRegistry.getInstance().trackSchema({{nameCamel}}Schema){{/if}}
11
+
12
+ export default {{nameCamel}}Schema