@hello.nrfcloud.com/proto-map 16.0.4 → 16.1.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.
package/api/Context.ts CHANGED
@@ -4,6 +4,7 @@ export const Context = {
4
4
  device: new URL(`${baseURL}/device`),
5
5
  deviceCredentials: new URL(`${baseURL}/device/credentials`),
6
6
  devices: new URL(`${baseURL}/devices`),
7
+ userDevices: new URL(`${baseURL}/user-devices`),
7
8
  deviceJWT: new URL(`${baseURL}/device-jwt`),
8
9
  userJWT: new URL(`${baseURL}/user-jwt`),
9
10
  apiHealth: new URL(`${baseURL}/api/health`),
@@ -0,0 +1,19 @@
1
+ import { IsoDateType } from './IsoDateType.js'
2
+ import { describe, test as it } from 'node:test'
3
+ import assert from 'node:assert/strict'
4
+ import { validate } from '../validate.js'
5
+
6
+ void describe('isoDateRegExp', () => {
7
+ void it('should match a date string', () => {
8
+ const isoTs = new Date().toISOString()
9
+ const maybeValid = validate(IsoDateType())(isoTs)
10
+ assert.equal('errors' in maybeValid, false)
11
+ assert.equal('value' in maybeValid && maybeValid?.value, isoTs)
12
+ })
13
+ void it('should validate a date string with local timezone', () => {
14
+ const isoTs = '2024-07-01T16:33:15+02:00'
15
+ const maybeValid = validate(IsoDateType())(isoTs)
16
+ assert.equal('errors' in maybeValid, false)
17
+ assert.equal('value' in maybeValid && maybeValid?.value, isoTs)
18
+ })
19
+ })
@@ -0,0 +1,9 @@
1
+ import { Type, type TString } from '@sinclair/typebox'
2
+
3
+ export const IsoDateType = (description?: string): TString =>
4
+ Type.String({
5
+ pattern:
6
+ '^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)(([+-]([0-9]{2}):([0-9]{2})|Z)?)$',
7
+ description: description ?? 'A date formatted as an ISO 8601 string',
8
+ examples: [new Date().toISOString()],
9
+ })
@@ -0,0 +1,19 @@
1
+ import { Type } from '@sinclair/typebox'
2
+ import { Context } from './Context.js'
3
+ import { DeviceId, PublicDeviceId } from './DeviceId.js'
4
+ import { IsoDateType } from './IsoDateType.js'
5
+ import { Model } from './Devices.js'
6
+
7
+ export const UserDevices = Type.Object({
8
+ '@context': Type.Literal(Context.userDevices.toString()),
9
+ devices: Type.Array(
10
+ Type.Object({
11
+ id: PublicDeviceId,
12
+ deviceId: DeviceId,
13
+ model: Model,
14
+ expires: IsoDateType(
15
+ 'The date when the device will be removed from the list of devices',
16
+ ),
17
+ }),
18
+ ),
19
+ })
package/api/index.ts CHANGED
@@ -7,3 +7,5 @@ export * from './UserJWT.js'
7
7
  export * from './APIHealth.js'
8
8
  export * from './DeviceCredentials.js'
9
9
  export * from './Email.js'
10
+ export * from './IsoDateType.js'
11
+ export * from './UserDevices.js'
@@ -3,6 +3,7 @@ export var Context = {
3
3
  device: new URL("".concat(baseURL, "/device")),
4
4
  deviceCredentials: new URL("".concat(baseURL, "/device/credentials")),
5
5
  devices: new URL("".concat(baseURL, "/devices")),
6
+ userDevices: new URL("".concat(baseURL, "/user-devices")),
6
7
  deviceJWT: new URL("".concat(baseURL, "/device-jwt")),
7
8
  userJWT: new URL("".concat(baseURL, "/user-jwt")),
8
9
  apiHealth: new URL("".concat(baseURL, "/api/health"))
@@ -0,0 +1,10 @@
1
+ import { Type } from '@sinclair/typebox';
2
+ export var IsoDateType = function(description) {
3
+ return Type.String({
4
+ pattern: '^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2}(?:.[0-9]*)?)(([+-]([0-9]{2}):([0-9]{2})|Z)?)$',
5
+ description: description !== null && description !== void 0 ? description : 'A date formatted as an ISO 8601 string',
6
+ examples: [
7
+ new Date().toISOString()
8
+ ]
9
+ });
10
+ };
@@ -0,0 +1,18 @@
1
+ import { IsoDateType } from './IsoDateType.js';
2
+ import { describe, test as it } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { validate } from '../validate.js';
5
+ void describe('isoDateRegExp', function() {
6
+ void it('should match a date string', function() {
7
+ var isoTs = new Date().toISOString();
8
+ var maybeValid = validate(IsoDateType())(isoTs);
9
+ assert.equal('errors' in maybeValid, false);
10
+ assert.equal('value' in maybeValid && (maybeValid === null || maybeValid === void 0 ? void 0 : maybeValid.value), isoTs);
11
+ });
12
+ void it('should validate a date string with local timezone', function() {
13
+ var isoTs = '2024-07-01T16:33:15+02:00';
14
+ var maybeValid = validate(IsoDateType())(isoTs);
15
+ assert.equal('errors' in maybeValid, false);
16
+ assert.equal('value' in maybeValid && (maybeValid === null || maybeValid === void 0 ? void 0 : maybeValid.value), isoTs);
17
+ });
18
+ });
@@ -0,0 +1,14 @@
1
+ import { Type } from '@sinclair/typebox';
2
+ import { Context } from './Context.js';
3
+ import { DeviceId, PublicDeviceId } from './DeviceId.js';
4
+ import { IsoDateType } from './IsoDateType.js';
5
+ import { Model } from './Devices.js';
6
+ export var UserDevices = Type.Object({
7
+ '@context': Type.Literal(Context.userDevices.toString()),
8
+ devices: Type.Array(Type.Object({
9
+ id: PublicDeviceId,
10
+ deviceId: DeviceId,
11
+ model: Model,
12
+ expires: IsoDateType('The date when the device will be removed from the list of devices')
13
+ }))
14
+ });
package/dist/api/index.js CHANGED
@@ -7,3 +7,5 @@ export * from './UserJWT.js';
7
7
  export * from './APIHealth.js';
8
8
  export * from './DeviceCredentials.js';
9
9
  export * from './Email.js';
10
+ export * from './IsoDateType.js';
11
+ export * from './UserDevices.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hello.nrfcloud.com/proto-map",
3
- "version": "16.0.4",
3
+ "version": "16.1.0",
4
4
  "description": "Documents the communication protocol between devices, the hello.nrfcloud.com/map backend and web application",
5
5
  "type": "module",
6
6
  "exports": {
@@ -39,8 +39,8 @@
39
39
  "@bifravst/prettier-config": "1.1.0",
40
40
  "@commitlint/config-conventional": "19.2.2",
41
41
  "@swc/cli": "0.4.0",
42
- "@swc/core": "1.7.6",
43
- "@types/node": "22.1.0",
42
+ "@swc/core": "1.7.10",
43
+ "@types/node": "22.2.0",
44
44
  "@types/xml2js": "0.4.14",
45
45
  "chalk": "5.3.0",
46
46
  "globstar": "1.0.0",
@@ -98,6 +98,6 @@
98
98
  "lwm2m"
99
99
  ],
100
100
  "peerDependencies": {
101
- "@sinclair/typebox": "^0.33.3"
101
+ "@sinclair/typebox": "^0.33.4"
102
102
  }
103
103
  }