@ossy/consultancy 3.24.1 → 3.26.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 (54) hide show
  1. package/README.md +7 -7
  2. package/package.json +7 -5
  3. package/src/ConsultancyNav.jsx +6 -6
  4. package/src/CreateConsultancyButton.jsx +21 -7
  5. package/src/Forecast.jsx +38 -37
  6. package/src/MonthDayGrid.jsx +18 -50
  7. package/src/RequestMatches.jsx +29 -19
  8. package/src/RequestStatsPanel.jsx +1 -1
  9. package/src/ResumeMatches.jsx +51 -0
  10. package/src/calendar-quarter-months.js +36 -0
  11. package/src/calendar-quarter-months.spec.js +22 -0
  12. package/src/create-company.flow.js +9 -9
  13. package/src/current-month.component.jsx +14 -25
  14. package/src/delete-company.flow.js +5 -5
  15. package/src/en.translations.json +17 -32
  16. package/src/extract-request.task.js +20 -13
  17. package/src/extract-request.task.spec.js +7 -3
  18. package/src/file-inbound-request.task.js +93 -0
  19. package/src/file-inbound-request.task.spec.js +118 -0
  20. package/src/forecast-figures.jsx +42 -0
  21. package/src/forecast-panels.jsx +29 -42
  22. package/src/index.js +0 -1
  23. package/src/intake-categories.js +6 -22
  24. package/src/kpi-trend.component.jsx +1 -1
  25. package/src/match-reasons.js +85 -0
  26. package/src/match-reasons.spec.js +73 -0
  27. package/src/match-resumes.js +12 -7
  28. package/src/match-resumes.spec.js +13 -8
  29. package/src/match-resumes.task.js +1 -22
  30. package/src/match-resumes.task.spec.js +19 -14
  31. package/src/{consultancy.page.jsx → overview.page.jsx} +7 -7
  32. package/src/refresh-matches.js +38 -0
  33. package/src/refresh-matches.spec.js +31 -1
  34. package/src/refresh-matches.task.js +322 -72
  35. package/src/refresh-matches.task.spec.js +229 -27
  36. package/src/request.schema.js +0 -1
  37. package/src/{resume-inbound-screening.task.js → resume-inbound-requests.task.js} +12 -14
  38. package/src/{resume-inbound-screening.task.spec.js → resume-inbound-requests.task.spec.js} +32 -18
  39. package/src/resumes.page.jsx +43 -12
  40. package/src/schema-ids.js +0 -1
  41. package/src/spend-for-month.js +67 -0
  42. package/src/spend-for-month.spec.js +41 -0
  43. package/src/spend-year.jsx +91 -0
  44. package/src/{org.page.jsx → spend.page.jsx} +14 -13
  45. package/src/sv.translations.json +17 -32
  46. package/src/use-chart-months.js +5 -2
  47. package/src/use-spend-by-month.js +52 -0
  48. package/src/utilization.component.jsx +1 -1
  49. package/src/view-forecasts.flow.js +3 -3
  50. package/src/year-totals.component.jsx +1 -1
  51. package/src/Overview.jsx +0 -91
  52. package/src/company-basic-info.schema.js +0 -25
  53. package/src/screen-inbound.task.js +0 -133
  54. package/src/screen-inbound.task.spec.js +0 -154
@@ -1,133 +0,0 @@
1
- import { forwardedOriginalFromMessage } from '@ossy/email/forwarded-original'
2
- import { location } from './locations.js'
3
- import { ConsultancySchema } from './schema-ids.js'
4
- import { requestSourceText } from './extract-request.task.js'
5
- import {
6
- INTAKE_CATEGORIES,
7
- acceptsRequestCategory,
8
- } from './intake-categories.js'
9
-
10
- const GetResource = { id: '@ossy/resources/actions/get' }
11
- const UpdateContent = { id: '@ossy/resources/actions/update-content' }
12
- const Categorize = { id: '@ossy/media-tasks/actions/categorize' }
13
- const ExtractRequest = { id: '@ossy/consultancy/actions/extract-request' }
14
- const INBOUND_MESSAGE = '@ossy/email/schema/inbound-message'
15
-
16
- export const metadata = {
17
- id: '@ossy/consultancy/tasks/screen-inbound',
18
- triggers: [
19
- {
20
- type: INBOUND_MESSAGE,
21
- event: 'Created',
22
- },
23
- ],
24
- outputs: [
25
- {
26
- name: 'request',
27
- kind: 'location',
28
- schemaId: ConsultancySchema.request,
29
- prefix: location,
30
- },
31
- ],
32
- }
33
-
34
- function fail (message, status) {
35
- throw Object.assign(new Error(message), { status })
36
- }
37
-
38
- function workspaceIdFrom ({ event, payload, req }) {
39
- return event?.payload?.belongsTo
40
- ?? event?.belongsTo
41
- ?? payload?.workspaceId
42
- ?? req?.workspaceId
43
- ?? null
44
- }
45
-
46
- async function saveContent (sdk, resource, workspaceId, patch) {
47
- const content = { ...resource.content, ...patch }
48
- const updated = await sdk.invoke(UpdateContent, {
49
- resourceId: resource.id,
50
- workspaceId,
51
- content,
52
- })
53
- return updated?.content ? updated : { ...resource, content }
54
- }
55
-
56
- /**
57
- * A forward stores the person who clicked forward as From. Replace that with
58
- * the sender inside the forwarded block, and remember who forwarded it.
59
- */
60
- async function withOriginalSender (sdk, resource, workspaceId) {
61
- const content = resource?.content && typeof resource.content === 'object' ? resource.content : {}
62
- if (content.forwardedBy) return resource
63
- const forward = forwardedOriginalFromMessage(content)
64
- if (!forward?.from) return resource
65
- return saveContent(sdk, resource, workspaceId, {
66
- from: forward.from,
67
- forwardedBy: content.from || '',
68
- ...(forward.subject ? { subject: forward.subject } : {}),
69
- ...(forward.receivedAt ? { receivedAt: forward.receivedAt } : {}),
70
- })
71
- }
72
-
73
- /**
74
- * New inbound mail is categorized first. A consultancy request is extracted.
75
- * The outcome is stored on the message so a later pass can finish a run that
76
- * died before the request was saved. Anything else stays in the inbox.
77
- */
78
- export async function run ({ event, payload, req, sdk }) {
79
- if (!sdk?.invoke) fail('sdk is required', 500)
80
-
81
- const resourceId = event?.resourceId || payload?.resourceId
82
- if (!resourceId) fail('resourceId is required', 400)
83
-
84
- const workspaceId = workspaceIdFrom({ event, payload, req })
85
- if (!workspaceId) fail('workspaceId is required', 400)
86
-
87
- let resource = await sdk.invoke(GetResource, { resourceId })
88
- if (resource?.type !== INBOUND_MESSAGE) fail('inbound message is required', 400)
89
- if (resource.content?.requestId) {
90
- return { skipped: false, requestId: resource.content.requestId, category: resource.content.intakeCategory ?? null }
91
- }
92
-
93
- resource = await withOriginalSender(sdk, resource, workspaceId)
94
-
95
- const alreadyScreened = Object.hasOwn(resource.content ?? {}, 'intakeCategory')
96
- let category = typeof resource.content?.intakeCategory === 'string' ? resource.content.intakeCategory : null
97
- let confidence = typeof resource.content?.intakeConfidence === 'number' ? resource.content.intakeConfidence : null
98
-
99
- if (!alreadyScreened) {
100
- const text = requestSourceText(resource)
101
- if (!text) {
102
- return { skipped: true, reason: 'empty', category: null, confidence: null }
103
- }
104
-
105
- const categorized = await sdk.invoke(Categorize, {
106
- workspaceId,
107
- text,
108
- categories: INTAKE_CATEGORIES,
109
- })
110
- category = typeof categorized?.category === 'string' ? categorized.category : null
111
- confidence = typeof categorized?.confidence === 'number' ? categorized.confidence : null
112
- resource = await saveContent(sdk, resource, workspaceId, {
113
- intakeCategory: category,
114
- intakeConfidence: confidence,
115
- })
116
- }
117
-
118
- if (!acceptsRequestCategory({ category, confidence })) {
119
- return { skipped: true, reason: 'category', category, confidence }
120
- }
121
-
122
- const request = await sdk.invoke(ExtractRequest, { resourceId, workspaceId })
123
- const requestId = request?.id ?? null
124
- if (requestId) {
125
- await saveContent(sdk, resource, workspaceId, { requestId })
126
- }
127
- return {
128
- skipped: false,
129
- category,
130
- confidence,
131
- requestId,
132
- }
133
- }
@@ -1,154 +0,0 @@
1
- import { metadata, run } from './screen-inbound.task.js'
2
- import { INTAKE_CATEGORIES, REQUEST_CATEGORY } from './intake-categories.js'
3
- import { requestSourceText } from './extract-request.task.js'
4
-
5
- const GetResource = { id: '@ossy/resources/actions/get' }
6
- const UpdateContent = { id: '@ossy/resources/actions/update-content' }
7
- const Categorize = { id: '@ossy/media-tasks/actions/categorize' }
8
- const ExtractRequest = { id: '@ossy/consultancy/actions/extract-request' }
9
-
10
- const inbound = {
11
- id: 'msg-1',
12
- type: '@ossy/email/schema/inbound-message',
13
- content: {
14
- from: 'Anna Berg <anna@client.se>',
15
- subject: 'Senior React, 6 manader',
16
- text: 'Vi soker en senior React-utvecklare i Stockholm.',
17
- messageId: 'assignment-1@client.se',
18
- },
19
- }
20
-
21
- function sdkFor (categorized, source = inbound) {
22
- let current = { ...source, content: { ...source.content } }
23
- const calls = []
24
- const sdk = {
25
- async invoke (action, payload) {
26
- calls.push({ id: action.id, payload })
27
- if (action.id === GetResource.id) return current
28
- if (action.id === UpdateContent.id) {
29
- current = { ...current, content: payload.content }
30
- return current
31
- }
32
- if (action.id === Categorize.id) return categorized
33
- if (action.id === ExtractRequest.id) return { id: 'request-1' }
34
- throw new Error(`unexpected ${action.id}`)
35
- },
36
- }
37
- return { calls, sdk }
38
- }
39
-
40
- describe('screen-inbound task', () => {
41
- it('listens for a new inbound message', () => {
42
- expect(metadata.triggers).toEqual([
43
- { type: '@ossy/email/schema/inbound-message', event: 'Created' },
44
- ])
45
- })
46
-
47
- it('extracts a request when the category is a confident consultancy request', async () => {
48
- const { calls, sdk } = sdkFor({ category: REQUEST_CATEGORY, confidence: 1 })
49
- const result = await run({
50
- event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
51
- sdk,
52
- })
53
-
54
- const categorize = calls.find((call) => call.id === Categorize.id)
55
- expect(categorize.payload).toMatchObject({
56
- workspaceId: 'ws-1',
57
- text: requestSourceText(inbound),
58
- categories: INTAKE_CATEGORIES,
59
- })
60
- expect(calls.map((call) => call.id)).toEqual([
61
- GetResource.id,
62
- Categorize.id,
63
- UpdateContent.id,
64
- ExtractRequest.id,
65
- UpdateContent.id,
66
- ])
67
- expect(calls.find((call) => call.id === ExtractRequest.id).payload).toEqual({
68
- resourceId: inbound.id,
69
- workspaceId: 'ws-1',
70
- })
71
- expect(calls.filter((call) => call.id === UpdateContent.id).at(-1).payload.content.requestId).toBe('request-1')
72
- expect(result).toEqual({
73
- skipped: false,
74
- category: REQUEST_CATEGORY,
75
- confidence: 1,
76
- requestId: 'request-1',
77
- })
78
- })
79
-
80
- it('leaves a contact message in the inbox', async () => {
81
- const { calls, sdk } = sdkFor({ category: 'contact', confidence: 0.99 })
82
- const result = await run({
83
- event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
84
- sdk,
85
- })
86
-
87
- expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
88
- expect(calls.find((call) => call.id === UpdateContent.id).payload.content.intakeCategory).toBe('contact')
89
- expect(result).toEqual({
90
- skipped: true,
91
- reason: 'category',
92
- category: 'contact',
93
- confidence: 0.99,
94
- })
95
- })
96
-
97
- it('leaves a low-confidence consultancy request in the inbox', async () => {
98
- const { calls, sdk } = sdkFor({ category: REQUEST_CATEGORY, confidence: 0.4 })
99
- const result = await run({
100
- event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
101
- sdk,
102
- })
103
-
104
- expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
105
- expect(result).toMatchObject({ skipped: true, reason: 'category', confidence: 0.4 })
106
- })
107
-
108
- it('extracts again when a confident label was saved and the request was not', async () => {
109
- const { calls, sdk } = sdkFor(null, {
110
- ...inbound,
111
- content: {
112
- ...inbound.content,
113
- intakeCategory: REQUEST_CATEGORY,
114
- intakeConfidence: 1,
115
- },
116
- })
117
- const result = await run({
118
- event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
119
- sdk,
120
- })
121
-
122
- expect(calls.map((call) => call.id)).not.toContain(Categorize.id)
123
- expect(calls.map((call) => call.id)).toContain(ExtractRequest.id)
124
- expect(result.requestId).toBe('request-1')
125
- })
126
-
127
- it('stores the original sender before screening a forward', async () => {
128
- const { calls, sdk } = sdkFor({ category: 'contact', confidence: 0.99 }, {
129
- ...inbound,
130
- content: {
131
- ...inbound.content,
132
- from: 'oskars.sylwan@ossy.se',
133
- subject: 'Fwd: Senior React',
134
- text: [
135
- '---------- Forwarded message ---------',
136
- 'From: Recruiter <recruiter@client.se>',
137
- 'Subject: Senior React',
138
- '',
139
- 'Vi soker en senior React-utvecklare i Stockholm.',
140
- ].join('\n'),
141
- },
142
- })
143
-
144
- await run({
145
- event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
146
- sdk,
147
- })
148
-
149
- const firstSave = calls.find((call) => call.id === UpdateContent.id)
150
- expect(firstSave.payload.content.from).toBe('recruiter@client.se')
151
- expect(firstSave.payload.content.forwardedBy).toBe('oskars.sylwan@ossy.se')
152
- expect(firstSave.payload.content.subject).toBe('Senior React')
153
- })
154
- })