@devkong/cli-nx 0.0.59 → 0.0.61

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devkong/cli-nx",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "typings": "./src/index.d.ts",
@@ -43,31 +43,6 @@ To automatically tag your code with an incremented version number (e.g., 1, 2, 3
43
43
  kong publish-version --verbose
44
44
  ```
45
45
 
46
- **NOTE:** before publishing a new version, ensure that your extension JSON Schema includes the required `operation` field. This input field has `enum` type and defines the action to be performed by the extension.
47
-
48
- **Purpose:**
49
-
50
- - When an extension supports multiple usage variants or endpoints, this field identifies the specific operation to execute.
51
- - It enables routing and logic selection within the extension workflow.
52
- - If an extension has only one primary function, this `enum` contains a single value that uniquely identifies its operation.
53
-
54
- **Usage Example:**
55
-
56
- ```
57
- "$schema": "http://json-schema.org/draft-07/schema#",
58
- "title": "Input",
59
- "type": "object",
60
- "properties": {
61
- "operation": {
62
- "enum": ["score digital profile", ...],
63
- "examples": ["score digital profile"],
64
- "description": "Operation type."
65
- },
66
- ...
67
- "required": ["operation", ... ]
68
- }
69
- ```
70
-
71
46
  ### List Available Versions
72
47
 
73
48
  To see all available versions of your extension, run:
@@ -23,9 +23,9 @@ repositories {
23
23
  }
24
24
 
25
25
  dependencies {
26
- implementation("io.kong:kong-sdk-function-template:${kongSdkVersion}")
27
- implementation("io.kong:kong-sdk-kotlin:${kongSdkVersion}")
28
- implementation("io.kong:kong-common:${kongVersion}")
26
+ implementation("io.kong:kong-sdk-function-template:$kongSdkVersion")
27
+ implementation("io.kong:kong-sdk-kotlin:$kongSdkVersion")
28
+ implementation("io.kong:kong-common:$kongVersion")
29
29
 
30
30
  implementation(enforcedPlatform("io.quarkus.platform:quarkus-bom:$quarkusVersion"))
31
31
  implementation("io.quarkus:quarkus-arc")
@@ -39,7 +39,7 @@ dependencies {
39
39
  testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesTestVersion")
40
40
  }
41
41
 
42
- group = "io.kong"
42
+ group = "io.kong.extension"
43
43
  version = "0.0.1-SNAPSHOT"
44
44
 
45
45
  java {
@@ -4,14 +4,14 @@ kotlin.code.style=official
4
4
  javaVersion=21
5
5
 
6
6
  # kong artifacts
7
- kongSdkVersion=0.0.19-SNAPSHOT
7
+ kongSdkVersion=0.0.20-SNAPSHOT
8
8
  kongVersion=0.0.1-SNAPSHOT
9
9
 
10
10
  # https://mvnrepository.com/artifact/org.jlleitschuh.gradle/ktlint-gradle
11
11
  jlleitschuhGradlePluginVersion=14.0.1
12
12
 
13
13
  #https://mvnrepository.com/artifact/com.networknt/json-schema-validator
14
- jsonSchemaValidatorVersion=3.0.0
14
+ jsonSchemaValidatorVersion=1.5.8
15
15
 
16
16
  # https://mvnrepository.com/artifact/io.github.khalilou88.jnxplus/jnxplus-gradle-plugin
17
17
  jnxplusGradlePluginVersion=0.4.0
@@ -6,6 +6,7 @@ import io.kong.sdk.KongFunction
6
6
  import io.kong.sdk.KongFunctionContext
7
7
  import io.kong.sdk.function.template.Field
8
8
  import io.quarkus.runtime.annotations.RegisterForReflection
9
+ import jakarta.inject.Inject
9
10
  import jakarta.inject.Singleton
10
11
 
11
12
  // This is the main entry point for developing an extension for Kong.
@@ -14,41 +15,47 @@ import jakarta.inject.Singleton
14
15
  // Define the structure of the input data that your extension will accept.
15
16
  // Be sure to include example values for each field. These examples help generate
16
17
  // sample objects in the UI, making it easier to work with the models.
18
+
17
19
  @RegisterForReflection
18
20
  data class InputData(
19
21
  // REPLACE BELLOW WITH YOUR FIELDS
20
-
21
- @Field(description = "An integer number", examples = ["1"])
22
- val a: Int,
23
-
24
- @Field(description = "An integer number", examples = ["2"])
25
- val b: Int,
22
+ @Field(description = "An integer number", examples = ["1"]) val a: Int,
23
+ @Field(description = "An integer number", examples = ["2"]) val b: Int,
26
24
  )
27
25
 
28
26
  @RegisterForReflection
29
27
  data class OutputData(
30
28
  // Define the structure of the output data that your extension will return.
31
29
  // REPLACE BELLOW WITH YOUR FIELDS
32
-
33
- @Field(description = "Result of a + b", examples = ["3"])
34
- val sum_of: Int,
35
-
30
+ @Field(description = "Result of a + b", examples = ["3"]) val sumOf: Int,
36
31
  @Field(
37
32
  description = "A string field",
38
33
  examples = ["This example extension returns sum of a and b"],
39
34
  default = "null",
40
- )
41
- val comment: String? = null,
35
+ ) val comment: String? = null,
42
36
  )
43
37
 
44
- val objectMapper = ObjectMapper()
45
-
46
38
  @Singleton
47
39
  class Main : KongFunction<InputData>(InputData::class.java) {
48
40
  private val logger = AppLogger(Main::class.simpleName)
49
41
 
42
+ @Inject
43
+ internal lateinit var jsonMapper: ObjectMapper
44
+
50
45
  override suspend fun handle(
51
46
  data: InputData,
52
47
  context: KongFunctionContext,
53
- ): ByteArray? = objectMapper.writeValueAsBytes(OutputData(sum_of = data.a + data.b))
48
+ ): ByteArray? {
49
+ logger.info("handle sum") {
50
+ it["a"] = data.a
51
+ it["b"] = data.b
52
+ }
53
+
54
+ return jsonMapper.writeValueAsBytes(
55
+ OutputData(
56
+ sumOf = data.a + data.b,
57
+ comment = "sum of ${data.a} and ${data.b}",
58
+ ),
59
+ )
60
+ }
54
61
  }
@@ -1,6 +1,7 @@
1
1
  quarkus.profile=local
2
2
  quarkus.log.level=INFO
3
3
  quarkus.log.console.format=%d{yyyy-MM-dd'T'HH:mm:ss,SSS} | %-5p | %s thread=%t module=%c{2.} %e%n
4
+
4
5
  quarkus.otel.enabled=true
5
6
  quarkus.otel.exporter.otlp.enabled=false
6
7
  quarkus.http.test-port=8083
@@ -1,22 +1,22 @@
1
- package io.kong.extensionapicall
1
+ package io.kong.extension
2
2
 
3
3
  import com.fasterxml.jackson.databind.ObjectMapper
4
- import io.kong.extension.InputData
5
- import io.kong.extension.Main
6
- import io.kong.extension.OutputData
4
+ import io.kong.sdk.function.template.ExtensionTestProfile
7
5
  import io.quarkus.test.junit.QuarkusTest
6
+ import io.quarkus.test.junit.TestProfile
8
7
  import jakarta.inject.Inject
9
8
  import kotlinx.coroutines.test.runTest
10
9
  import org.junit.jupiter.api.Assertions.assertEquals
11
10
  import org.junit.jupiter.api.Test
12
11
 
13
12
  @QuarkusTest
13
+ @TestProfile(ExtensionTestProfile::class)
14
14
  class Test {
15
15
  @Inject
16
16
  lateinit var extension: Main
17
17
 
18
18
  @Inject
19
- lateinit var objectMapper: ObjectMapper
19
+ lateinit var jsonMapper: ObjectMapper
20
20
 
21
21
  @Test
22
22
  fun `when provided valid input then returns expected result`() =
@@ -24,9 +24,8 @@ class Test {
24
24
  val input = InputData(a = 1, b = 2)
25
25
 
26
26
  val bytes = extension.handle(input)
27
- val output = objectMapper.readValue(bytes, OutputData::class.java)
28
- val sumOf = output.sum_of
27
+ val output = jsonMapper.readValue(bytes, OutputData::class.java)
29
28
 
30
- assertEquals(3, sumOf)
29
+ assertEquals(3, output.sumOf)
31
30
  }
32
31
  }