@wwkit/harness 1.0.33 → 1.0.34
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/LICENSE +21 -21
- package/README.md +128 -128
- package/agents/scrum.md +206 -186
- package/agents/sprint.md +130 -121
- package/bin/index.js +291 -226
- package/commands/fix.md +87 -87
- package/commands/git-sync.md +217 -217
- package/commands/net-port.md +364 -364
- package/commands/pytest.md +10 -10
- package/commands/resume.md +104 -104
- package/commands/tl.md +11 -11
- package/commands/tsl.md +12 -0
- package/package.json +5 -4
- package/plugin.js +19 -19
- package/readme/development.md +39 -39
- package/readme/publish.md +41 -41
- package/readme/testing.md +44 -44
- package/scripts/postinstall.js +58 -58
- package/skills/better-skill/SKILL.md +192 -124
- package/skills/blame-skill/SKILL.md +148 -201
- package/skills/blame-skill/references/scoring-rules.md +190 -0
- package/skills/blame-sprint-agent/SKILL.md +167 -0
- package/skills/blame-sprint-agent/references/scoring-rules.md +113 -0
- package/skills/blame-sprint-skill/SKILL.md +154 -0
- package/skills/blame-sprint-skill/references/scoring-rules.md +101 -0
- package/skills/extract/SKILL.md +119 -119
- package/skills/extract/references/build-xpath.js +30 -30
- package/skills/extract/references/clean-html.js +90 -90
- package/skills/extract/references/detail.md +54 -54
- package/skills/extract/references/detail.schema.json5 +48 -48
- package/skills/extract/references/extract-detail.js +71 -71
- package/skills/extract/references/extract-regex.js +81 -81
- package/skills/extract/references/extract-sample.js +48 -48
- package/skills/extract/references/list-rule-gen.md +109 -109
- package/skills/extract/references/list.md +134 -134
- package/skills/extract/references/list.schema.json5 +33 -33
- package/skills/extract/references/navi.md +44 -44
- package/skills/extract/references/navi.schema.json5 +23 -23
- package/skills/extract/references/text.md +40 -40
- package/skills/extract/references/text.schema.json5 +21 -21
- package/skills/extract/references/to-text.js +20 -20
- package/skills/extract/references/validate-schema.js +39 -39
- package/skills/jstest/SKILL.md +561 -561
- package/skills/jstest/references/case-create.md +327 -327
- package/skills/jstest/references/case-fix.md +273 -273
- package/skills/jstest/references/config.md +148 -148
- package/skills/jstest/references/coverage-analyze.md +247 -247
- package/skills/jstest/references/env-ensure.md +210 -210
- package/skills/jstest/references/execute.md +168 -168
- package/skills/jstest/references/sample.md +166 -166
- package/skills/jstest/references/scoring-rules.md +75 -75
- package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
- package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
- package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
- package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
- package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
- package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
- package/skills/jstest/references/src/jstest-sample/index.js +6 -6
- package/skills/jstest/references/suitability-check.md +232 -232
- package/skills/jstest/references/test-standards.md +288 -288
- package/skills/lint/SKILL.md +440 -440
- package/skills/lint/references/ai-fix.md +137 -137
- package/skills/lint/references/config-setup.md +102 -102
- package/skills/lint/references/config.md +65 -65
- package/skills/lint/references/detect-language.js +65 -65
- package/skills/lint/references/env-ensure.md +88 -88
- package/skills/lint/references/language-detect.md +75 -75
- package/skills/lint/references/languages/js.md +110 -110
- package/skills/lint/references/languages/py.md +89 -89
- package/skills/lint/references/rules-analyze.md +125 -125
- package/skills/lint/references/suitability-check.md +81 -81
- package/skills/lint/references/tool-fix.md +90 -90
- package/skills/new-skill/SKILL.md +193 -227
- package/skills/pytest/SKILL.md +555 -555
- package/skills/pytest/references/case-create.md +324 -324
- package/skills/pytest/references/case-fix.md +271 -271
- package/skills/pytest/references/config.md +145 -145
- package/skills/pytest/references/coverage-analyze.md +223 -223
- package/skills/pytest/references/env-ensure.md +195 -195
- package/skills/pytest/references/execute.md +152 -152
- package/skills/pytest/references/sample.md +159 -159
- package/skills/pytest/references/scoring-rules.md +57 -57
- package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
- package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
- package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
- package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
- package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
- package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
- package/skills/pytest/references/suitability-check.md +220 -220
- package/skills/pytest/references/test-standards.md +244 -244
- package/skills/query/SKILL.md +71 -71
- package/skills/read-docs/SKILL.md +134 -134
- package/skills/read-docs/references/opencode/agents/cases.md +206 -206
- package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
- package/skills/read-docs/references/opencode/agents/detail.md +191 -191
- package/skills/read-docs/references/opencode/agents/examples.md +100 -100
- package/skills/read-docs/references/opencode/agents/index.md +309 -309
- package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
- package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
- package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
- package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
- package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
- package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
- package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
- package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
- package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
- package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
- package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
- package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
- package/skills/read-docs/references/opencode/cli/env.md +38 -38
- package/skills/read-docs/references/opencode/cli/index.md +18 -18
- package/skills/read-docs/references/opencode/cli/tui.md +35 -35
- package/skills/read-docs/references/opencode/commands/examples.md +42 -42
- package/skills/read-docs/references/opencode/commands/index.md +185 -185
- package/skills/read-docs/references/opencode/config/provider.md +151 -151
- package/skills/read-docs/references/opencode/formatter/index.md +70 -70
- package/skills/read-docs/references/opencode/guide/config.md +419 -419
- package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
- package/skills/read-docs/references/opencode/guide/index.md +37 -37
- package/skills/read-docs/references/opencode/guide/providers.md +31 -31
- package/skills/read-docs/references/opencode/guide/rules.md +63 -63
- package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
- package/skills/read-docs/references/opencode/plugins/index.md +188 -188
- package/skills/read-docs/references/opencode/reference/index.md +118 -118
- package/skills/read-docs/references/opencode/rule/index.md +77 -77
- package/skills/read-docs/references/opencode/skills/detail.md +113 -113
- package/skills/read-docs/references/opencode/skills/examples.md +141 -141
- package/skills/read-docs/references/opencode/skills/index.md +126 -126
- package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
- package/skills/read-docs/references/opencode/tests/agent.md +9 -9
- package/skills/read-docs/references/opencode/tests/config.md +59 -59
- package/skills/read-docs/references/opencode/tests/file.md +11 -11
- package/skills/read-docs/references/opencode/tests/serve.md +17 -17
- package/skills/read-docs/references/opencode/tests/session.md +30 -30
- package/skills/read-docs/references/opencode/tests/web.md +16 -16
- package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
- package/skills/read-docs/references/opencode/tools/context.md +17 -17
- package/skills/read-docs/references/opencode/tools/custom.md +110 -110
- package/skills/read-docs/references/opencode/tools/detail.md +104 -104
- package/skills/read-docs/references/opencode/tools/examples.md +71 -71
- package/skills/read-docs/references/opencode/tools/index.md +56 -56
- package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
- package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
- package/skills/read-docs/references/opencode/train/README.md +134 -134
- package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
- package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
- package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
- package/skills/read-docs/references/opencode/train/index.md +163 -163
- package/skills/read-docs/references/opencode/train/practice.md +872 -872
- package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
- package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
- package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
- package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
- package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
- package/skills/read-docs/references/opencode/tui/index.md +26 -26
- package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
- package/skills/read-docs/references/superpowers/comparison.md +77 -77
- package/skills/read-docs/references/superpowers/context.md +71 -71
- package/skills/read-docs/references/superpowers/index.md +58 -58
- package/skills/read-docs/references/superpowers/parallel.md +49 -49
- package/skills/read-docs/references/superpowers/sdd.md +183 -183
- package/skills/read-docs/references/superpowers/skills.md +68 -68
- package/skills/read-docs/references/superpowers/workflow.md +83 -83
- package/skills/revise/SKILL.md +121 -121
- package/skills/revise/references/article.md +36 -36
- package/skills/revise/references/article.schema.json5 +40 -40
- package/skills/revise/references/gallery.md +34 -34
- package/skills/revise/references/gallery.schema.json5 +40 -40
- package/skills/revise/references/question.md +32 -32
- package/skills/revise/references/question.schema.json5 +31 -31
- package/skills/revise/references/status.md +31 -31
- package/skills/revise/references/status.schema.json5 +27 -27
- package/skills/revise/references/validate-schema.js +39 -39
- package/skills/step-extract/SKILL.md +205 -0
- package/skills/tsl/SKILL.md +393 -0
- package/skills/tsl/package.json +10 -0
- package/skills/tsl/references/global-review-rules.md +25 -0
- package/skills/tsl/references/prepare-prompt.md +150 -0
- package/skills/tsl/references/terminology-rules.md +93 -0
- package/skills/tsl/references/translation-guide.md +23 -0
- package/skills/tsl/references/translation-prompt.md +115 -0
- package/skills/tsl/references/translation-rules.md +48 -0
- package/skills/tsl/references/verification-rules.md +58 -0
- package/skills/tsl/scripts/check-boundaries.js +140 -0
- package/skills/tsl/scripts/chunk-text.js +144 -0
- package/skills/tsl/scripts/clean-text.js +121 -0
- package/skills/tsl/scripts/cleanup-glossary.js +160 -0
- package/skills/tsl/scripts/extract-pdf.js +94 -0
- package/skills/tsl/scripts/generate-review.js +179 -0
- package/skills/tsl/scripts/merge-result.js +164 -0
- package/skills/tsl/scripts/verify-chunk.js +170 -0
- package/skills/tsl-format/SKILL.md +298 -0
- package/skills/tsl-format/references/format-prompt.md +103 -0
- package/skills/tsl-format/references/format-rules.md +58 -0
- package/skills/tsl-format/scripts/chunk-bilingual.js +96 -0
- package/skills/tsl-format/scripts/merge-format.js +105 -0
- package/src/config.js +29 -29
- package/src/config.json5 +19 -19
- package/skills/new-skill/references/template.md +0 -53
- package/skills/new-skill/references/workflow-patterns.md +0 -104
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
export class OrderService {
|
|
2
|
-
|
|
3
|
-
static TRANSITIONS = {
|
|
4
|
-
'created': ['paid', 'cancelled'],
|
|
5
|
-
'paid': ['shipped', 'refunded'],
|
|
6
|
-
'shipped': ['delivered', 'returned'],
|
|
7
|
-
'delivered': ['returned'],
|
|
8
|
-
'cancelled': [],
|
|
9
|
-
'refunded': [],
|
|
10
|
-
'returned': []
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
constructor(baseUrl = 'https://api.example.com') {
|
|
14
|
-
this.baseUrl = baseUrl
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
_getDiscount(amount) {
|
|
18
|
-
if (amount > 1000) {
|
|
19
|
-
return 0.10
|
|
20
|
-
} else if (amount > 500) {
|
|
21
|
-
return 0.05
|
|
22
|
-
} else if (amount > 100) {
|
|
23
|
-
return 0.03
|
|
24
|
-
}
|
|
25
|
-
return 0.0
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_getTax(amount) {
|
|
29
|
-
if (amount > 500) {
|
|
30
|
-
return 0.08
|
|
31
|
-
} else if (amount > 100) {
|
|
32
|
-
return 0.05
|
|
33
|
-
}
|
|
34
|
-
return 0.0
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async createOrder(userId, items) {
|
|
38
|
-
const total = items.reduce((sum, item) => sum + (item.price || 0) * (item.quantity || 1), 0)
|
|
39
|
-
const discount = this._getDiscount(total)
|
|
40
|
-
const tax = this._getTax(total)
|
|
41
|
-
const discounted = total * (1 - discount)
|
|
42
|
-
const taxed = discounted * (1 + tax)
|
|
43
|
-
const response = await fetch(`${this.baseUrl}/orders`, {
|
|
44
|
-
method: 'POST',
|
|
45
|
-
headers: { 'Content-Type': 'application/json' },
|
|
46
|
-
body: JSON.stringify({
|
|
47
|
-
user_id: userId,
|
|
48
|
-
items,
|
|
49
|
-
total: Math.round(taxed * 100) / 100,
|
|
50
|
-
status: 'created',
|
|
51
|
-
created_at: new Date().toISOString()
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
return response.json()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async updateStatus(orderId, newStatus) {
|
|
58
|
-
const response = await fetch(`${this.baseUrl}/orders/${orderId}`)
|
|
59
|
-
const order = await response.json()
|
|
60
|
-
const currentStatus = order.status
|
|
61
|
-
const allowed = OrderService.TRANSITIONS[currentStatus] || []
|
|
62
|
-
if (!allowed.includes(newStatus)) {
|
|
63
|
-
throw new Error(`Cannot transition from ${currentStatus} to ${newStatus}`)
|
|
64
|
-
}
|
|
65
|
-
const patchResponse = await fetch(`${this.baseUrl}/orders/${orderId}`, {
|
|
66
|
-
method: 'PATCH',
|
|
67
|
-
headers: { 'Content-Type': 'application/json' },
|
|
68
|
-
body: JSON.stringify({ status: newStatus })
|
|
69
|
-
})
|
|
70
|
-
return patchResponse.json()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async getOrder(orderId) {
|
|
74
|
-
const response = await fetch(`${this.baseUrl}/orders/${orderId}`)
|
|
75
|
-
if (response.status === 404) {
|
|
76
|
-
return null
|
|
77
|
-
}
|
|
78
|
-
return response.json()
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async cancelOrder(orderId) {
|
|
82
|
-
return this.updateStatus(orderId, 'cancelled')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async listOrders(userId) {
|
|
86
|
-
const response = await fetch(`${this.baseUrl}/orders?user_id=${userId}`)
|
|
87
|
-
return response.json()
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
calculateTotal(items) {
|
|
91
|
-
const total = items.reduce((sum, item) => sum + (item.price || 0) * (item.quantity || 1), 0)
|
|
92
|
-
const discount = this._getDiscount(total)
|
|
93
|
-
const tax = this._getTax(total)
|
|
94
|
-
const discounted = total * (1 - discount)
|
|
95
|
-
const taxed = discounted * (1 + tax)
|
|
96
|
-
return Math.round(taxed * 100) / 100
|
|
97
|
-
}
|
|
98
|
-
}
|
|
1
|
+
export class OrderService {
|
|
2
|
+
|
|
3
|
+
static TRANSITIONS = {
|
|
4
|
+
'created': ['paid', 'cancelled'],
|
|
5
|
+
'paid': ['shipped', 'refunded'],
|
|
6
|
+
'shipped': ['delivered', 'returned'],
|
|
7
|
+
'delivered': ['returned'],
|
|
8
|
+
'cancelled': [],
|
|
9
|
+
'refunded': [],
|
|
10
|
+
'returned': []
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(baseUrl = 'https://api.example.com') {
|
|
14
|
+
this.baseUrl = baseUrl
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_getDiscount(amount) {
|
|
18
|
+
if (amount > 1000) {
|
|
19
|
+
return 0.10
|
|
20
|
+
} else if (amount > 500) {
|
|
21
|
+
return 0.05
|
|
22
|
+
} else if (amount > 100) {
|
|
23
|
+
return 0.03
|
|
24
|
+
}
|
|
25
|
+
return 0.0
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_getTax(amount) {
|
|
29
|
+
if (amount > 500) {
|
|
30
|
+
return 0.08
|
|
31
|
+
} else if (amount > 100) {
|
|
32
|
+
return 0.05
|
|
33
|
+
}
|
|
34
|
+
return 0.0
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async createOrder(userId, items) {
|
|
38
|
+
const total = items.reduce((sum, item) => sum + (item.price || 0) * (item.quantity || 1), 0)
|
|
39
|
+
const discount = this._getDiscount(total)
|
|
40
|
+
const tax = this._getTax(total)
|
|
41
|
+
const discounted = total * (1 - discount)
|
|
42
|
+
const taxed = discounted * (1 + tax)
|
|
43
|
+
const response = await fetch(`${this.baseUrl}/orders`, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: { 'Content-Type': 'application/json' },
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
user_id: userId,
|
|
48
|
+
items,
|
|
49
|
+
total: Math.round(taxed * 100) / 100,
|
|
50
|
+
status: 'created',
|
|
51
|
+
created_at: new Date().toISOString()
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
return response.json()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async updateStatus(orderId, newStatus) {
|
|
58
|
+
const response = await fetch(`${this.baseUrl}/orders/${orderId}`)
|
|
59
|
+
const order = await response.json()
|
|
60
|
+
const currentStatus = order.status
|
|
61
|
+
const allowed = OrderService.TRANSITIONS[currentStatus] || []
|
|
62
|
+
if (!allowed.includes(newStatus)) {
|
|
63
|
+
throw new Error(`Cannot transition from ${currentStatus} to ${newStatus}`)
|
|
64
|
+
}
|
|
65
|
+
const patchResponse = await fetch(`${this.baseUrl}/orders/${orderId}`, {
|
|
66
|
+
method: 'PATCH',
|
|
67
|
+
headers: { 'Content-Type': 'application/json' },
|
|
68
|
+
body: JSON.stringify({ status: newStatus })
|
|
69
|
+
})
|
|
70
|
+
return patchResponse.json()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getOrder(orderId) {
|
|
74
|
+
const response = await fetch(`${this.baseUrl}/orders/${orderId}`)
|
|
75
|
+
if (response.status === 404) {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
return response.json()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async cancelOrder(orderId) {
|
|
82
|
+
return this.updateStatus(orderId, 'cancelled')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async listOrders(userId) {
|
|
86
|
+
const response = await fetch(`${this.baseUrl}/orders?user_id=${userId}`)
|
|
87
|
+
return response.json()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
calculateTotal(items) {
|
|
91
|
+
const total = items.reduce((sum, item) => sum + (item.price || 0) * (item.quantity || 1), 0)
|
|
92
|
+
const discount = this._getDiscount(total)
|
|
93
|
+
const tax = this._getTax(total)
|
|
94
|
+
const discounted = total * (1 - discount)
|
|
95
|
+
const taxed = discounted * (1 + tax)
|
|
96
|
+
return Math.round(taxed * 100) / 100
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import crypto from 'crypto'
|
|
2
|
-
|
|
3
|
-
export class TokenGenerator {
|
|
4
|
-
|
|
5
|
-
static generateToken(length = 32) {
|
|
6
|
-
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
7
|
-
let result = ''
|
|
8
|
-
for (let i = 0; i < length; i++) {
|
|
9
|
-
result += chars[Math.floor(Math.random() * chars.length)]
|
|
10
|
-
}
|
|
11
|
-
return result
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static generateTokenWithTimestamp(length = 16) {
|
|
15
|
-
const timestamp = String(Date.now() / 1000)
|
|
16
|
-
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
17
|
-
let randomPart = ''
|
|
18
|
-
for (let i = 0; i < length; i++) {
|
|
19
|
-
randomPart += chars[Math.floor(Math.random() * chars.length)]
|
|
20
|
-
}
|
|
21
|
-
return `${timestamp}${randomPart}`
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static generateUuidLike() {
|
|
25
|
-
const chars = '0123456789abcdef'
|
|
26
|
-
let randomPart = ''
|
|
27
|
-
for (let i = 0; i < 32; i++) {
|
|
28
|
-
randomPart += chars[Math.floor(Math.random() * chars.length)]
|
|
29
|
-
}
|
|
30
|
-
const parts = [
|
|
31
|
-
randomPart.slice(0, 8),
|
|
32
|
-
randomPart.slice(8, 12),
|
|
33
|
-
randomPart.slice(12, 16),
|
|
34
|
-
randomPart.slice(16, 20),
|
|
35
|
-
randomPart.slice(20, 31)
|
|
36
|
-
]
|
|
37
|
-
return parts.join('-')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static generateHash(data, algorithm = 'sha256') {
|
|
41
|
-
if (typeof data === 'string') {
|
|
42
|
-
data = Buffer.from(data, 'utf-8')
|
|
43
|
-
}
|
|
44
|
-
const hasher = crypto.createHash(algorithm)
|
|
45
|
-
hasher.update(data)
|
|
46
|
-
return hasher.digest('hex')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static generateBatch(count, length = 32) {
|
|
50
|
-
const tokens = []
|
|
51
|
-
for (let i = 0; i < count; i++) {
|
|
52
|
-
tokens.push(TokenGenerator.generateToken(length))
|
|
53
|
-
}
|
|
54
|
-
return tokens
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static validateTokenLength(token, expectedLength) {
|
|
58
|
-
return token.length === expectedLength
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
|
|
3
|
+
export class TokenGenerator {
|
|
4
|
+
|
|
5
|
+
static generateToken(length = 32) {
|
|
6
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
7
|
+
let result = ''
|
|
8
|
+
for (let i = 0; i < length; i++) {
|
|
9
|
+
result += chars[Math.floor(Math.random() * chars.length)]
|
|
10
|
+
}
|
|
11
|
+
return result
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static generateTokenWithTimestamp(length = 16) {
|
|
15
|
+
const timestamp = String(Date.now() / 1000)
|
|
16
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
|
17
|
+
let randomPart = ''
|
|
18
|
+
for (let i = 0; i < length; i++) {
|
|
19
|
+
randomPart += chars[Math.floor(Math.random() * chars.length)]
|
|
20
|
+
}
|
|
21
|
+
return `${timestamp}${randomPart}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static generateUuidLike() {
|
|
25
|
+
const chars = '0123456789abcdef'
|
|
26
|
+
let randomPart = ''
|
|
27
|
+
for (let i = 0; i < 32; i++) {
|
|
28
|
+
randomPart += chars[Math.floor(Math.random() * chars.length)]
|
|
29
|
+
}
|
|
30
|
+
const parts = [
|
|
31
|
+
randomPart.slice(0, 8),
|
|
32
|
+
randomPart.slice(8, 12),
|
|
33
|
+
randomPart.slice(12, 16),
|
|
34
|
+
randomPart.slice(16, 20),
|
|
35
|
+
randomPart.slice(20, 31)
|
|
36
|
+
]
|
|
37
|
+
return parts.join('-')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static generateHash(data, algorithm = 'sha256') {
|
|
41
|
+
if (typeof data === 'string') {
|
|
42
|
+
data = Buffer.from(data, 'utf-8')
|
|
43
|
+
}
|
|
44
|
+
const hasher = crypto.createHash(algorithm)
|
|
45
|
+
hasher.update(data)
|
|
46
|
+
return hasher.digest('hex')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static generateBatch(count, length = 32) {
|
|
50
|
+
const tokens = []
|
|
51
|
+
for (let i = 0; i < count; i++) {
|
|
52
|
+
tokens.push(TokenGenerator.generateToken(length))
|
|
53
|
+
}
|
|
54
|
+
return tokens
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static validateTokenLength(token, expectedLength) {
|
|
58
|
+
return token.length === expectedLength
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
export class UserService {
|
|
2
|
-
|
|
3
|
-
constructor(baseUrl = 'https://api.example.com') {
|
|
4
|
-
this.baseUrl = baseUrl
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
validateEmail(email) {
|
|
8
|
-
const pattern = /^[\w.+-]+@[\w-]+\.[\w.]{2}$/
|
|
9
|
-
return pattern.test(email)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async createUser(username, email) {
|
|
13
|
-
if (!username) {
|
|
14
|
-
throw new Error('Username is required')
|
|
15
|
-
}
|
|
16
|
-
if (!this.validateEmail(email)) {
|
|
17
|
-
throw new Error('Invalid email format')
|
|
18
|
-
}
|
|
19
|
-
const response = await fetch(`${this.baseUrl}/users`, {
|
|
20
|
-
method: 'POST',
|
|
21
|
-
headers: { 'Content-Type': 'application/json' },
|
|
22
|
-
body: JSON.stringify({ username, email })
|
|
23
|
-
})
|
|
24
|
-
return response.json()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async getUser(userId) {
|
|
28
|
-
const response = await fetch(`${this.baseUrl}/users/${userId}`)
|
|
29
|
-
if (response.status === 404) {
|
|
30
|
-
return null
|
|
31
|
-
}
|
|
32
|
-
return response.json()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async updateLastLogin(userId) {
|
|
36
|
-
const now = new Date()
|
|
37
|
-
const response = await fetch(`${this.baseUrl}/users/${userId}`, {
|
|
38
|
-
method: 'PATCH',
|
|
39
|
-
headers: { 'Content-Type': 'application/json' },
|
|
40
|
-
body: JSON.stringify({ last_login: now.toISOString() })
|
|
41
|
-
})
|
|
42
|
-
return response.json()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async searchUsers(query) {
|
|
46
|
-
const response = await fetch(`${this.baseUrl}/users?q=${encodeURIComponent(query)}`)
|
|
47
|
-
return response.json()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async deleteUser(userId) {
|
|
51
|
-
const response = await fetch(`${this.baseUrl}/users/${userId}`, {
|
|
52
|
-
method: 'DELETE'
|
|
53
|
-
})
|
|
54
|
-
return response.status === 204
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
export class UserService {
|
|
2
|
+
|
|
3
|
+
constructor(baseUrl = 'https://api.example.com') {
|
|
4
|
+
this.baseUrl = baseUrl
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
validateEmail(email) {
|
|
8
|
+
const pattern = /^[\w.+-]+@[\w-]+\.[\w.]{2}$/
|
|
9
|
+
return pattern.test(email)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async createUser(username, email) {
|
|
13
|
+
if (!username) {
|
|
14
|
+
throw new Error('Username is required')
|
|
15
|
+
}
|
|
16
|
+
if (!this.validateEmail(email)) {
|
|
17
|
+
throw new Error('Invalid email format')
|
|
18
|
+
}
|
|
19
|
+
const response = await fetch(`${this.baseUrl}/users`, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: { 'Content-Type': 'application/json' },
|
|
22
|
+
body: JSON.stringify({ username, email })
|
|
23
|
+
})
|
|
24
|
+
return response.json()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async getUser(userId) {
|
|
28
|
+
const response = await fetch(`${this.baseUrl}/users/${userId}`)
|
|
29
|
+
if (response.status === 404) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
return response.json()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async updateLastLogin(userId) {
|
|
36
|
+
const now = new Date()
|
|
37
|
+
const response = await fetch(`${this.baseUrl}/users/${userId}`, {
|
|
38
|
+
method: 'PATCH',
|
|
39
|
+
headers: { 'Content-Type': 'application/json' },
|
|
40
|
+
body: JSON.stringify({ last_login: now.toISOString() })
|
|
41
|
+
})
|
|
42
|
+
return response.json()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async searchUsers(query) {
|
|
46
|
+
const response = await fetch(`${this.baseUrl}/users?q=${encodeURIComponent(query)}`)
|
|
47
|
+
return response.json()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async deleteUser(userId) {
|
|
51
|
+
const response = await fetch(`${this.baseUrl}/users/${userId}`, {
|
|
52
|
+
method: 'DELETE'
|
|
53
|
+
})
|
|
54
|
+
return response.status === 204
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Calculator } from './Calculator.js'
|
|
2
|
-
export { UserService } from './UserService.js'
|
|
3
|
-
export { FileProcessor } from './FileProcessor.js'
|
|
4
|
-
export { TokenGenerator } from './TokenGenerator.js'
|
|
5
|
-
export { ConfigManager } from './ConfigManager.js'
|
|
6
|
-
export { OrderService } from './OrderService.js'
|
|
1
|
+
export { Calculator } from './Calculator.js'
|
|
2
|
+
export { UserService } from './UserService.js'
|
|
3
|
+
export { FileProcessor } from './FileProcessor.js'
|
|
4
|
+
export { TokenGenerator } from './TokenGenerator.js'
|
|
5
|
+
export { ConfigManager } from './ConfigManager.js'
|
|
6
|
+
export { OrderService } from './OrderService.js'
|