@3sixty/telemetry-rest-client 0.20.0-next.0 → 0.20.0-next.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,0BAA0B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./telemetryRestClient.js\";\n"]}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,0BAA0B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./telemetryRestClient.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"telemetryRestClient.js","sourceRoot":"","sources":["../../src/telemetryRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACN,gBAAgB,EAIhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAsB9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACtD;;OAEG;IACI,MAAM,CAAU,UAAU,yBAAyC;IAE1E;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,mBAAmB,CAAC,UAAU,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAA6C;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QACnC,MAAM,CAAC,WAAW,CAAC,mBAAmB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAEnE,MAAM,IAAI,CAAC,KAAK,CACf,aAAa,EACb,UAAU,CAAC,MAAM,EACjB;YACC,UAAU,EAAE;gBACX,EAAE;aACF;SACD,CACD,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,KAAK,CACjB,IAAiB,EACjB,MAAe,EACf,KAAc;QAYd,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAC9B,SAAS,EACT,UAAU,CAAC,GAAG,EACd;YACC,KAAK,EAAE;gBACN,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBACzB,MAAM;gBACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC3B;SACD,CACD,CAAC;QAEF,OAAO,MAAM,CAAC,IAAI,CAAC;IACpB,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,WAAW,CACvB,EAAU,EACV,SAAkB,EAClB,OAAgB,EAChB,MAAe,EACf,KAAc;QAed,MAAM,CAAC,WAAW,CAAC,mBAAmB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAEnE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAC9B,mBAAmB,EACnB,UAAU,CAAC,GAAG,EACd;YACC,UAAU,EAAE;gBACX,EAAE;aACF;YACD,KAAK,EAAE;gBACN,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;gBACnC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC/B,MAAM;gBACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC3B;SACD,CACD,CAAC;QAEF,OAAO,MAAM,CAAC,IAAI,CAAC;IACpB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@3sixty/api-core\";\nimport {\n\tHttpHeaderHelper,\n\ttype IBaseRestClientConfig,\n\ttype ICreatedResponse,\n\ttype INoContentResponse\n} from \"@3sixty/api-models\";\nimport { Coerce, Guards } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport type {\n\tITelemetryAddMetricValueRequest,\n\tITelemetryComponent,\n\tITelemetryCreateMetricRequest,\n\tITelemetryGetMetricRequest,\n\tITelemetryGetMetricResponse,\n\tITelemetryGetMetricValueRequest,\n\tITelemetryGetMetricValueResponse,\n\tITelemetryListRequest,\n\tITelemetryMetricValueEntry,\n\tITelemetryListResponse,\n\tITelemetryMetric,\n\tITelemetryMetricValue,\n\tITelemetryRemoveMetricRequest,\n\tITelemetryUpdateMetricRequest,\n\tITelemetryValuesListRequest,\n\tITelemetryValuesListResponse,\n\tMetricCounterOperation,\n\tMetricType\n} from \"@3sixty/telemetry-models\";\nimport { HttpMethod } from \"@3sixty/web\";\n\n/**\n * Client for performing telemetry through to REST endpoints.\n */\nexport class TelemetryRestClient extends BaseRestClient implements ITelemetryComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TelemetryRestClient>();\n\n\t/**\n\t * Create a new instance of TelemetryRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(TelemetryRestClient.CLASS_NAME, config, \"telemetry\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TelemetryRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create one or more metrics.\n\t * @param metric The metric details, or the details of several metrics.\n\t * @returns A promise that resolves when the metrics have been created.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric | ITelemetryMetric[]): Promise<void> {\n\t\tGuards.defined(TelemetryRestClient.CLASS_NAME, nameof(metric), metric);\n\n\t\tawait this.fetch<ITelemetryCreateMetricRequest, ICreatedResponse>(\"/metric\", HttpMethod.POST, {\n\t\t\tbody: metric\n\t\t});\n\t}\n\n\t/**\n\t * Get the metric details and it's most recent value.\n\t * @param id The metric id.\n\t * @returns The metric details and it's most recent value.\n\t */\n\tpublic async getMetric(id: string): Promise<{\n\t\tmetric: ITelemetryMetric;\n\t\tvalue?: ITelemetryMetricValue;\n\t}> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<ITelemetryGetMetricRequest, ITelemetryGetMetricResponse>(\n\t\t\t\"/metric/:id\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get a specific metric value by its id.\n\t * @param id The id of the metric.\n\t * @param valueId The id of the metric value.\n\t * @returns The metric value.\n\t */\n\tpublic async getMetricValue(id: string, valueId: string): Promise<ITelemetryMetricValue> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, nameof(valueId), valueId);\n\n\t\tconst response = await this.fetch<\n\t\t\tITelemetryGetMetricValueRequest,\n\t\t\tITelemetryGetMetricValueResponse\n\t\t>(\"/metric/:id/value/:valueId\", HttpMethod.GET, {\n\t\t\tpathParams: { id, valueId }\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been updated.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryRestClient.CLASS_NAME, nameof(metric), metric);\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, nameof(metric.id), metric.id);\n\n\t\tawait this.fetch<ITelemetryUpdateMetricRequest, INoContentResponse>(\n\t\t\t\"/metric/:id\",\n\t\t\tHttpMethod.PUT,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid: metric.id\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tlabel: metric.label,\n\t\t\t\t\tdescription: metric.description,\n\t\t\t\t\tunit: metric.unit\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Add a metric value.\n\t * @param id The id of the metric.\n\t * @param value The value for the add operation.\n\t * @param customData The custom data for the add operation.\n\t * @returns The created metric value id.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, nameof(id), id);\n\t\tGuards.defined(TelemetryRestClient.CLASS_NAME, nameof(value), value);\n\n\t\tconst response = await this.fetch<ITelemetryAddMetricValueRequest, ICreatedResponse>(\n\t\t\t\"/metric/:id/value\",\n\t\t\tHttpMethod.POST,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tvalue,\n\t\t\t\t\tcustomData\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn HttpHeaderHelper.extractId(\n\t\t\tresponse.headers,\n\t\t\t`${this.getPathPrefix()}/metric/:metricId/value/:id`\n\t\t);\n\t}\n\n\t/**\n\t * Add multiple metric values.\n\t * @param values The metric values to add.\n\t * @returns The created metric value ids, in the order the values were supplied.\n\t */\n\tpublic async addMetricValues(values: ITelemetryMetricValueEntry[]): Promise<string[]> {\n\t\tGuards.array<ITelemetryMetricValueEntry>(\n\t\t\tTelemetryRestClient.CLASS_NAME,\n\t\t\tnameof(values),\n\t\t\tvalues\n\t\t);\n\n\t\t// The REST surface records one value per request, so each value becomes a request.\n\t\tconst valueIds: string[] = [];\n\t\tfor (const entry of values) {\n\t\t\tvalueIds.push(await this.addMetricValue(entry.id, entry.value, entry.customData));\n\t\t}\n\t\treturn valueIds;\n\t}\n\n\t/**\n\t * Remove metric.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric and all its values have been removed.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<ITelemetryRemoveMetricRequest, INoContentResponse>(\n\t\t\t\"/metric/:id\",\n\t\t\tHttpMethod.DELETE,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Query the metrics.\n\t * @param type The type of the metric.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async query(\n\t\ttype?: MetricType,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metrics.\n\t\t */\n\t\tentities: ITelemetryMetric[];\n\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst result = await this.fetch<ITelemetryListRequest, ITelemetryListResponse>(\n\t\t\t\"/metric\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Coerce.string(type),\n\t\t\t\t\tcursor,\n\t\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn result.body;\n\t}\n\n\t/**\n\t * Query the metric values.\n\t * @param id The id of the metric.\n\t * @param timeStart The inclusive time as the start of the metric entries.\n\t * @param timeEnd The inclusive time as the end of the metric entries.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async queryValues(\n\t\tid: string,\n\t\ttimeStart?: number,\n\t\ttimeEnd?: number,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metric details.\n\t\t */\n\t\tmetric: ITelemetryMetric;\n\t\t/**\n\t\t * The values for the metric.\n\t\t */\n\t\tentities: ITelemetryMetricValue[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst result = await this.fetch<ITelemetryValuesListRequest, ITelemetryValuesListResponse>(\n\t\t\t\"/metric/:id/value\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttimeStart: Coerce.string(timeStart),\n\t\t\t\t\ttimeEnd: Coerce.string(timeEnd),\n\t\t\t\t\tcursor,\n\t\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn result.body;\n\t}\n}\n"]}
1
+ {"version":3,"file":"telemetryRestClient.js","sources":["../../src/telemetryRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACN,gBAAgB,EAIhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAsB9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACtD;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,qBAAqB,CAAC;IAElE;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,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BACN,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;gBACnC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC/B,MAAM;gBACN,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aAC3B;SACD,CACD,CAAC;QAEF,OAAO,MAAM,CAAC,IAAI,CAAC;IACpB,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@3sixty/api-core\";\nimport {\n\tHttpHeaderHelper,\n\ttype IBaseRestClientConfig,\n\ttype ICreatedResponse,\n\ttype INoContentResponse\n} from \"@3sixty/api-models\";\nimport { Coerce, Guards } from \"@3sixty/core\";\n\nimport type {\n\tITelemetryAddMetricValueRequest,\n\tITelemetryComponent,\n\tITelemetryCreateMetricRequest,\n\tITelemetryGetMetricRequest,\n\tITelemetryGetMetricResponse,\n\tITelemetryGetMetricValueRequest,\n\tITelemetryGetMetricValueResponse,\n\tITelemetryListRequest,\n\tITelemetryMetricValueEntry,\n\tITelemetryListResponse,\n\tITelemetryMetric,\n\tITelemetryMetricValue,\n\tITelemetryRemoveMetricRequest,\n\tITelemetryUpdateMetricRequest,\n\tITelemetryValuesListRequest,\n\tITelemetryValuesListResponse,\n\tMetricCounterOperation,\n\tMetricType\n} from \"@3sixty/telemetry-models\";\nimport { HttpMethod } from \"@3sixty/web\";\n\n/**\n * Client for performing telemetry through to REST endpoints.\n */\nexport class TelemetryRestClient extends BaseRestClient implements ITelemetryComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"TelemetryRestClient\";\n\n\t/**\n\t * Create a new instance of TelemetryRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(TelemetryRestClient.CLASS_NAME, config, \"telemetry\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TelemetryRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create one or more metrics.\n\t * @param metric The metric details, or the details of several metrics.\n\t * @returns A promise that resolves when the metrics have been created.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric | ITelemetryMetric[]): Promise<void> {\n\t\tGuards.defined(TelemetryRestClient.CLASS_NAME, \"metric\", metric);\n\n\t\tawait this.fetch<ITelemetryCreateMetricRequest, ICreatedResponse>(\"/metric\", HttpMethod.POST, {\n\t\t\tbody: metric\n\t\t});\n\t}\n\n\t/**\n\t * Get the metric details and it's most recent value.\n\t * @param id The metric id.\n\t * @returns The metric details and it's most recent value.\n\t */\n\tpublic async getMetric(id: string): Promise<{\n\t\tmetric: ITelemetryMetric;\n\t\tvalue?: ITelemetryMetricValue;\n\t}> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, \"id\", id);\n\n\t\tconst response = await this.fetch<ITelemetryGetMetricRequest, ITelemetryGetMetricResponse>(\n\t\t\t\"/metric/:id\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Get a specific metric value by its id.\n\t * @param id The id of the metric.\n\t * @param valueId The id of the metric value.\n\t * @returns The metric value.\n\t */\n\tpublic async getMetricValue(id: string, valueId: string): Promise<ITelemetryMetricValue> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, \"id\", id);\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, \"valueId\", valueId);\n\n\t\tconst response = await this.fetch<\n\t\t\tITelemetryGetMetricValueRequest,\n\t\t\tITelemetryGetMetricValueResponse\n\t\t>(\"/metric/:id/value/:valueId\", HttpMethod.GET, {\n\t\t\tpathParams: { id, valueId }\n\t\t});\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been updated.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryRestClient.CLASS_NAME, \"metric\", metric);\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, \"metric.id\", metric.id);\n\n\t\tawait this.fetch<ITelemetryUpdateMetricRequest, INoContentResponse>(\n\t\t\t\"/metric/:id\",\n\t\t\tHttpMethod.PUT,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid: metric.id\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tlabel: metric.label,\n\t\t\t\t\tdescription: metric.description,\n\t\t\t\t\tunit: metric.unit\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Add a metric value.\n\t * @param id The id of the metric.\n\t * @param value The value for the add operation.\n\t * @param customData The custom data for the add operation.\n\t * @returns The created metric value id.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, \"id\", id);\n\t\tGuards.defined(TelemetryRestClient.CLASS_NAME, \"value\", value);\n\n\t\tconst response = await this.fetch<ITelemetryAddMetricValueRequest, ICreatedResponse>(\n\t\t\t\"/metric/:id/value\",\n\t\t\tHttpMethod.POST,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tbody: {\n\t\t\t\t\tvalue,\n\t\t\t\t\tcustomData\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn HttpHeaderHelper.extractId(\n\t\t\tresponse.headers,\n\t\t\t`${this.getPathPrefix()}/metric/:metricId/value/:id`\n\t\t);\n\t}\n\n\t/**\n\t * Add multiple metric values.\n\t * @param values The metric values to add.\n\t * @returns The created metric value ids, in the order the values were supplied.\n\t */\n\tpublic async addMetricValues(values: ITelemetryMetricValueEntry[]): Promise<string[]> {\n\t\tGuards.array<ITelemetryMetricValueEntry>(\n\t\t\tTelemetryRestClient.CLASS_NAME,\n\t\t\t\"values\",\n\t\t\tvalues\n\t\t);\n\n\t\t// The REST surface records one value per request, so each value becomes a request.\n\t\tconst valueIds: string[] = [];\n\t\tfor (const entry of values) {\n\t\t\tvalueIds.push(await this.addMetricValue(entry.id, entry.value, entry.customData));\n\t\t}\n\t\treturn valueIds;\n\t}\n\n\t/**\n\t * Remove metric.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric and all its values have been removed.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, \"id\", id);\n\n\t\tawait this.fetch<ITelemetryRemoveMetricRequest, INoContentResponse>(\n\t\t\t\"/metric/:id\",\n\t\t\tHttpMethod.DELETE,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n\n\t/**\n\t * Query the metrics.\n\t * @param type The type of the metric.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async query(\n\t\ttype?: MetricType,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metrics.\n\t\t */\n\t\tentities: ITelemetryMetric[];\n\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst result = await this.fetch<ITelemetryListRequest, ITelemetryListResponse>(\n\t\t\t\"/metric\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Coerce.string(type),\n\t\t\t\t\tcursor,\n\t\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn result.body;\n\t}\n\n\t/**\n\t * Query the metric values.\n\t * @param id The id of the metric.\n\t * @param timeStart The inclusive time as the start of the metric entries.\n\t * @param timeEnd The inclusive time as the end of the metric entries.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async queryValues(\n\t\tid: string,\n\t\ttimeStart?: number,\n\t\ttimeEnd?: number,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metric details.\n\t\t */\n\t\tmetric: ITelemetryMetric;\n\t\t/**\n\t\t * The values for the metric.\n\t\t */\n\t\tentities: ITelemetryMetricValue[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(TelemetryRestClient.CLASS_NAME, \"id\", id);\n\n\t\tconst result = await this.fetch<ITelemetryValuesListRequest, ITelemetryValuesListResponse>(\n\t\t\t\"/metric/:id/value\",\n\t\t\tHttpMethod.GET,\n\t\t\t{\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttimeStart: Coerce.string(timeStart),\n\t\t\t\t\ttimeEnd: Coerce.string(timeEnd),\n\t\t\t\t\tcursor,\n\t\t\t\t\tlimit: Coerce.string(limit)\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn result.body;\n\t}\n}\n"]}
package/docs/changelog.md CHANGED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ ## [0.20.0-next.2](https://github.com/3sixtyglobal/telemetry/compare/telemetry-rest-client-v0.20.0-next.1...telemetry-rest-client-v0.20.0-next.2) (2026-10-26)
4
+
5
+
6
+ ### Features
7
+
8
+ * release to next [skip ci] ([#22](https://github.com/3sixtyglobal/telemetry/issues/22)) ([274c07f](https://github.com/3sixtyglobal/telemetry/commit/274c07f0f0f405c55b73703933759223435e1f70))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @3sixty/telemetry-models bumped from 0.20.0-next.1 to 0.20.0-next.2
16
+
17
+ ## [0.20.0-next.1](https://github.com/3sixtyglobal/telemetry/compare/telemetry-rest-client-v0.20.0-next.0...telemetry-rest-client-v0.20.0-next.1) (2026-10-23)
18
+
19
+
20
+ ### Features
21
+
22
+ * publish packages under the [@3sixty](https://github.com/3sixty) namespace ([e488a8c](https://github.com/3sixtyglobal/telemetry/commit/e488a8cbe26251de694077a0164af480cab61c3a))
23
+ * updated ts compile ([4490a7b](https://github.com/3sixtyglobal/telemetry/commit/4490a7b854bdea72a79946d2dbb708a47e81b56f))
24
+
25
+
26
+ ### Dependencies
27
+
28
+ * The following workspace dependencies were updated
29
+ * dependencies
30
+ * @3sixty/telemetry-models bumped from 0.20.0-next.0 to 0.20.0-next.1
@@ -194,6 +194,8 @@ The value for the add operation.
194
194
 
195
195
  ##### customData?
196
196
 
197
+ \{\[`key`: `string`\]: `unknown`; \}
198
+
197
199
  The custom data for the add operation.
198
200
 
199
201
  #### Returns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sixty/telemetry-rest-client",
3
- "version": "0.20.0-next.0",
3
+ "version": "0.20.0-next.2",
4
4
  "description": "REST client for interacting with telemetry service endpoints.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,15 +11,15 @@
11
11
  "license": "Apache-2.0",
12
12
  "type": "module",
13
13
  "engines": {
14
- "node": ">=24.0.0"
14
+ "node": ">=24.0.0",
15
+ "bun": ">=1.4.4"
15
16
  },
16
17
  "dependencies": {
17
18
  "@3sixty/api-core": "next",
18
19
  "@3sixty/api-models": "next",
19
20
  "@3sixty/core": "next",
20
- "@3sixty/entity": "next",
21
21
  "@3sixty/nameof": "next",
22
- "@3sixty/telemetry-models": "0.20.0-next.0",
22
+ "@3sixty/telemetry-models": "0.20.0-next.2",
23
23
  "@3sixty/web": "next"
24
24
  },
25
25
  "main": "./dist/es/index.js",