@certik/skynet 0.18.0 → 0.18.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.1
4
+
5
+ - BREAKING: opensearch feature has been replaced by elastic search
6
+ - Fixed: s3 library listKeys function when search result is empty
7
+
3
8
  ## 0.18.0
4
9
 
5
10
  - BREAKING: remove dependencies on `SKYNET_AWS_ACCESS_KEY_ID` and `SKYNET_AWS_SECRET_ACCESS_KEY` and `SKYNET_AWS_REGION`
package/bun.lockb CHANGED
Binary file
package/opsgenie.d.ts CHANGED
@@ -3,5 +3,6 @@ export function postGenieMessage<T>(
3
3
  alias?: string;
4
4
  message: string;
5
5
  },
6
+ apiKey: string,
6
7
  verbose?: boolean,
7
8
  ): Promise<{ result: T }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -19,7 +19,7 @@
19
19
  "@aws-sdk/client-s3": "^3.478.0",
20
20
  "@aws-sdk/client-sqs": "^3.478.0",
21
21
  "@aws-sdk/lib-dynamodb": "^3.478.0",
22
- "@opensearch-project/opensearch": "^2.4.0",
22
+ "@elastic/elasticsearch": "^8.14.0",
23
23
  "@slack/web-api": "^6.11.0",
24
24
  "bottleneck": "^2.19.5",
25
25
  "chalk": "^5.3.0",
package/s3.js CHANGED
@@ -135,6 +135,10 @@ async function listKeys(bucketname, prefix, continuationToken) {
135
135
  throw `unable to list keys with prefix ${prefix}: ${err}`;
136
136
  }
137
137
 
138
+ if (!data.Contents) {
139
+ return { keys: [] };
140
+ }
141
+
138
142
  let res = { keys: data.Contents.map(({ Key }) => Key) };
139
143
  if (data.IsTruncated) {
140
144
  res.continuationToken = data.NextContinuationToken;
package/search.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export function sendToSearch<T>(
2
+ appName: string,
3
+ indexPrefix: string,
4
+ record: string,
5
+ throws?: boolean,
6
+ ): Promise<{ status: string; result: T }>;
package/search.js ADDED
@@ -0,0 +1,29 @@
1
+ import { isProduction } from "./env.js";
2
+ import { inline } from "./log.js";
3
+ import { Client } from "@elastic/elasticsearch";
4
+ import osModule from "os";
5
+
6
+ export async function sendToSearch(appName, indexPrefix, record, throws = false) {
7
+ const client = new Client({
8
+ cloud: { id: process.env.SKYNET_ELASTICSEARCH_CLOUD_ID },
9
+ auth: { apiKey: process.env.SKYNET_ELASTICSEARCH_API_KEY },
10
+ });
11
+
12
+ const now = new Date();
13
+ const indexName = [indexPrefix, isProduction() ? "prod" : "dev", now.toISOString().slice(0, 7)].join("-");
14
+
15
+ // best as possible delivery
16
+ // by default not throw
17
+ try {
18
+ await client.index({
19
+ index: indexName,
20
+ document: { app: appName, instance: osModule.hostname(), timestamp: now, record },
21
+ });
22
+ } catch (err) {
23
+ inline.error(err);
24
+
25
+ if (throws) {
26
+ throw err;
27
+ }
28
+ }
29
+ }
package/opensearch.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Client, ClientOptions } from "@opensearch-project/opensearch";
2
-
3
- export declare function newOpensearchClient(
4
- endpoint: string,
5
- key: string,
6
- secret: string,
7
- options?: ClientOptions,
8
- ): Client;
9
-
10
- export declare async function sendToOpensearch<T>(
11
- client: Client,
12
- appName: string,
13
- index: string,
14
- record: string,
15
- indexSuffixes?: string[],
16
- ): Promise<{ status: string; result: T }>;
package/opensearch.js DELETED
@@ -1,34 +0,0 @@
1
- import { Client } from "@opensearch-project/opensearch";
2
-
3
- // newOpensearchClient creates a new opensearch client with the given endpoint, key, secret and extra opensearch client options.
4
- export function newOpensearchClient(endpoint, key, secret, options = {}) {
5
- return new Client({
6
- node: endpoint,
7
- auth: {
8
- username: key,
9
- password: secret,
10
- },
11
- ...options,
12
- });
13
- }
14
-
15
- // sendToOpensearch sends a record object to the given index using the given opensearch client. An appName is also attached to the record
16
- // as an identifier for who sends the record. The indexSuffixes is an array of strings that will be appended to the index name using `-`.
17
- // A typical usage of indexSuffixes could be the date e.g. ["2023", "08"] so that new indexes are created on the monthly basis to prevent
18
- // the index from growing too large.
19
- // Returns an object with status and result properties. The status is either "ok" or "error". The result is the response from opensearch
20
- // if the status is "ok" or the error message if the status is "error".
21
- export async function sendToOpensearch(client, appName, index, record, indexSuffixes = []) {
22
- try {
23
- const result = await client.index({
24
- index: indexSuffixes ? [index, ...indexSuffixes].join("-") : index,
25
- body: { app: appName, timestamp: new Date(), record },
26
- });
27
- if (result.statusCode === 201) {
28
- return { status: "ok", result };
29
- }
30
- return { status: "error", result };
31
- } catch (err) {
32
- return { status: "error", result: err.stack ? err.stack : err };
33
- }
34
- }