Skip to content

Commit

Permalink
feat: switch to ESM
Browse files Browse the repository at this point in the history
Closes #572
  • Loading branch information
coderbyheart committed Jan 7, 2022
1 parent 1249a65 commit 90d01a0
Show file tree
Hide file tree
Showing 123 changed files with 1,800 additions and 1,410 deletions.
3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion agps/cacheKey.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cacheKey } from './cacheKey'
import { cacheKey } from './cacheKey.js'

describe('cacheKey', () => {
it('should create a cache key', () =>
Expand Down
2 changes: 1 addition & 1 deletion agps/cacheKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Static } from '@sinclair/typebox'
import { agpsRequestSchema } from './types'
import { agpsRequestSchema } from './types.js'

export const cacheKey = ({
request,
Expand Down
14 changes: 7 additions & 7 deletions agps/deviceRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import {
IoTDataPlaneClient,
PublishCommand,
} from '@aws-sdk/client-iot-data-plane'
import { SFNClient, StartExecutionCommand } from '@aws-sdk/client-sfn'
import {
SQSClient,
SendMessageBatchCommand,
SendMessageBatchRequestEntry,
SQSClient,
} from '@aws-sdk/client-sqs'
import { SFNClient, StartExecutionCommand } from '@aws-sdk/client-sfn'
import { Static } from '@sinclair/typebox'
import { SQSEvent, SQSMessageAttributes } from 'aws-lambda'
import { isRight } from 'fp-ts/lib/These'
import { v4 } from 'uuid'
import { fromEnv } from '../util/fromEnv'
import { cacheKey } from './cacheKey'
import { AGPSDataCache, getCache } from './getCache'
import { Static } from '@sinclair/typebox'
import { agpsRequestSchema } from './types'
import { fromEnv } from '../util/fromEnv.js'
import { cacheKey } from './cacheKey.js'
import { AGPSDataCache, getCache } from './getCache.js'
import { agpsRequestSchema } from './types.js'

const {
binHoursString,
Expand Down
6 changes: 3 additions & 3 deletions agps/getCache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb'
import { ErrorInfo, ErrorType } from '../api/ErrorInfo'
import { unmarshall } from '@aws-sdk/util-dynamodb'
import { Either, right, left } from 'fp-ts/lib/Either'
import { Static } from '@sinclair/typebox'
import { agpsRequestSchema } from './types'
import { Either, left, right } from 'fp-ts/lib/Either'
import { ErrorInfo, ErrorType } from '../api/ErrorInfo.js'
import { agpsRequestSchema } from './types.js'

export type AGPSDataCache = Static<typeof agpsRequestSchema> & {
source: string
Expand Down
4 changes: 2 additions & 2 deletions api/validateWithJSONSchema.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { validateWithJSONSchema } from './validateWithJSONSchema'
import { Type, Static } from '@sinclair/typebox'
import { Static, Type } from '@sinclair/typebox'
import { isRight, Right } from 'fp-ts/lib/Either'
import { isLeft } from 'fp-ts/lib/These'
import { validateWithJSONSchema } from './validateWithJSONSchema.js'

const typedInputSchema = Type.Object(
{
Expand Down
6 changes: 3 additions & 3 deletions api/validateWithJSONSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as E from 'fp-ts/lib/Either'
import Ajv from 'ajv'
import { Static, TSchema } from '@sinclair/typebox'
import { ErrorInfo, ErrorType } from './ErrorInfo'
import Ajv from 'ajv'
import * as E from 'fp-ts/lib/Either'
import { ErrorInfo, ErrorType } from './ErrorInfo.js'

export const validateWithJSONSchema = <T extends TSchema>(
schema: T,
Expand Down
21 changes: 12 additions & 9 deletions cdk/apps/AssetTracker.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { App } from 'aws-cdk-lib'
import { AssetTrackerStack } from '../stacks/AssetTracker/stack'
import { WebAppStack } from '../stacks/WebApp'
import { FirmwareCIStack } from '../stacks/FirmwareCI'
import * as path from 'path'
import { readFileSync } from 'fs'
import { ContinuousDeploymentStack } from '../stacks/ContinuousDeployment'
import { extractRepoAndOwner } from '../helper/extract-repo-and-owner'
import { enabledInContext } from '../helper/enabledInContext'
import { PackedLambdas } from '../helper/lambdas/PackedLambdas'
import { AssetTrackerLambdas, CDKLambdas } from '../stacks/AssetTracker/lambdas'
import * as path from 'path'
import { enabledInContext } from '../helper/enabledInContext.js'
import { extractRepoAndOwner } from '../helper/extract-repo-and-owner.js'
import { PackedLambdas } from '../helper/lambdas/PackedLambdas.js'
import {
AssetTrackerLambdas,
CDKLambdas,
} from '../stacks/AssetTracker/lambdas.js'
import { AssetTrackerStack } from '../stacks/AssetTracker/stack.js'
import { ContinuousDeploymentStack } from '../stacks/ContinuousDeployment.js'
import { FirmwareCIStack } from '../stacks/FirmwareCI.js'
import { WebAppStack } from '../stacks/WebApp.js'

export class AssetTrackerApp extends App {
public constructor(args: {
Expand Down
6 changes: 3 additions & 3 deletions cdk/apps/HTTPAPIMock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { App } from 'aws-cdk-lib'
import { PackedLambdas } from '../helper/lambdas/PackedLambdas'
import { HttpApiMockStack } from '../test-resources/HttpApiMockStack'
import { HTTPAPIMockLambdas } from '../test-resources/prepare-test-resources'
import { PackedLambdas } from '../helper/lambdas/PackedLambdas.js'
import { HttpApiMockStack } from '../test-resources/HttpApiMockStack.js'
import { HTTPAPIMockLambdas } from '../test-resources/prepare-test-resources.js'

/**
* This sets up the parts of the app needed for the end-to-end tests
Expand Down
2 changes: 1 addition & 1 deletion cdk/apps/LambdaSourceCodeStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from 'aws-cdk-lib'
import { LambdaSourceCodeStorageStack } from '../stacks/LambdaSourceCodeStorage'
import { LambdaSourceCodeStorageStack } from '../stacks/LambdaSourceCodeStorage.js'

/**
* In order to deploy lambda functions written in TypeScript we need to publish
Expand Down
11 changes: 7 additions & 4 deletions cdk/apps/Test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { App } from 'aws-cdk-lib'
import { PackedLambdas } from '../helper/lambdas/PackedLambdas'
import { AssetTrackerLambdas, CDKLambdas } from '../stacks/AssetTracker/lambdas'
import { AssetTrackerStack } from '../stacks/AssetTracker/stack'
import { FirmwareCIStack } from '../stacks/FirmwareCI'
import { PackedLambdas } from '../helper/lambdas/PackedLambdas.js'
import {
AssetTrackerLambdas,
CDKLambdas,
} from '../stacks/AssetTracker/lambdas.js'
import { AssetTrackerStack } from '../stacks/AssetTracker/stack.js'
import { FirmwareCIStack } from '../stacks/FirmwareCI.js'

/**
* This sets up the parts of the app needed for the end-to-end tests
Expand Down
8 changes: 4 additions & 4 deletions cdk/cloudformation-http-api-mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HTTPAPIMockApp } from './apps/HTTPAPIMock'
import { getLambdaSourceCodeBucketName } from './helper/getLambdaSourceCodeBucketName'
import { preparePackagedLambdaStorageDir } from './helper/lambdas/outDir'
import { prepareHTTPAPIMockLambdas } from './test-resources/prepare-test-resources'
import { HTTPAPIMockApp } from './apps/HTTPAPIMock.js'
import { getLambdaSourceCodeBucketName } from './helper/getLambdaSourceCodeBucketName.js'
import { preparePackagedLambdaStorageDir } from './helper/lambdas/outDir.js'
import { prepareHTTPAPIMockLambdas } from './test-resources/prepare-test-resources.js'

const rootDir = process.cwd()

Expand Down
2 changes: 1 addition & 1 deletion cdk/cloudformation-sourcecode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { LambdaSourceCodeStorageApp } from './apps/LambdaSourceCodeStorage'
import { LambdaSourceCodeStorageApp } from './apps/LambdaSourceCodeStorage.js'

new LambdaSourceCodeStorageApp().synth()
8 changes: 4 additions & 4 deletions cdk/cloudformation-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TestApp } from './apps/Test'
import { getLambdaSourceCodeBucketName } from './helper/getLambdaSourceCodeBucketName'
import { preparePackagedLambdaStorageDir } from './helper/lambdas/outDir'
import { TestApp } from './apps/Test.js'
import { getLambdaSourceCodeBucketName } from './helper/getLambdaSourceCodeBucketName.js'
import { preparePackagedLambdaStorageDir } from './helper/lambdas/outDir.js'
import {
prepareAssetTrackerLambdas,
prepareCDKLambdas,
} from './stacks/AssetTracker/lambdas'
} from './stacks/AssetTracker/lambdas.js'

const rootDir = process.cwd()

Expand Down
22 changes: 11 additions & 11 deletions cdk/cloudformation.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { AssetTrackerApp } from './apps/AssetTracker'
import { SSMClient } from '@aws-sdk/client-ssm'
import { getApiSettings } from '../third-party/unwiredlabs.com/unwiredlabs'
import chalk from 'chalk'
import {
getAGPSLocationApiSettings,
getCellLocationApiSettings,
getPGPSLocationApiSettings,
serviceKeyProperty,
} from '../third-party/nrfcloud.com/settings'
import { warn } from './helper/note'
import { CORE_STACK_NAME } from './stacks/stackName'
import { getSettings } from '../util/settings'
import * as chalk from 'chalk'
} from '../third-party/nrfcloud.com/settings.js'
import { getApiSettings } from '../third-party/unwiredlabs.com/unwiredlabs.js'
import { getSettings } from '../util/settings.js'
import { AssetTrackerApp } from './apps/AssetTracker.js'
import { getLambdaSourceCodeBucketName } from './helper/getLambdaSourceCodeBucketName.js'
import { getStackContexts } from './helper/getStackContexts.js'
import { preparePackagedLambdaStorageDir } from './helper/lambdas/outDir.js'
import { warn } from './helper/note.js'
import {
prepareAssetTrackerLambdas,
prepareCDKLambdas,
} from './stacks/AssetTracker/lambdas'
import { preparePackagedLambdaStorageDir } from './helper/lambdas/outDir'
import { getLambdaSourceCodeBucketName } from './helper/getLambdaSourceCodeBucketName'
import { getStackContexts } from './helper/getStackContexts'
} from './stacks/AssetTracker/lambdas.js'
import { CORE_STACK_NAME } from './stacks/stackName.js'

const ssm = new SSMClient({})
const fetchUnwiredLabsApiSettings = getApiSettings({
Expand Down
4 changes: 2 additions & 2 deletions cdk/createThingGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
ListThingsInThingGroupCommand,
UpdateCertificateCommand,
} from '@aws-sdk/client-iot'
import { CloudFormationCustomResourceEvent } from 'aws-lambda'
import { paginate } from '../util/paginate'
import {
cfnResponse,
ResponseStatus,
} from '@nordicsemiconductor/cloudformation-helpers'
import { CloudFormationCustomResourceEvent } from 'aws-lambda'
import { paginate } from '../util/paginate.js'

const iot = new IoTClient({})

Expand Down
6 changes: 3 additions & 3 deletions cdk/helper/addFakeRoute.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { stackOutput } from '@nordicsemiconductor/cloudformation-helpers'
import {
ApiGatewayV2Client,
CreateRouteCommand,
} from '@aws-sdk/client-apigatewayv2'
import { CloudFormationClient } from '@aws-sdk/client-cloudformation'
import { StackOutputs } from '../stacks/AssetTracker/stack'
import { CORE_STACK_NAME } from '../stacks/stackName'
import { stackOutput } from '@nordicsemiconductor/cloudformation-helpers'
import { v4 } from 'uuid'
import { StackOutputs } from '../stacks/AssetTracker/stack.js'
import { CORE_STACK_NAME } from '../stacks/stackName.js'

/**
* This creates a fake route after CloudFormation has finished deploying the
Expand Down
4 changes: 2 additions & 2 deletions cdk/helper/checkRegion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as chalk from 'chalk'
import { supportedRegions } from '../regions'
import chalk from 'chalk'
import { supportedRegions } from '../regions.js'

export const checkRegion = (): void => {
if (!supportedRegions.includes(process.env.AWS_REGION ?? 'us-east-1')) {
Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/enabledInContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import { Node } from 'constructs'
import * as chalk from 'chalk'

const ENABLED = 'enabled'
const DISABLED = 'disabled'
Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/extract-repo-and-owner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractRepoAndOwner } from './extract-repo-and-owner'
import { extractRepoAndOwner } from './extract-repo-and-owner.js'

describe('extractRepoAndOwner()', () => {
it('should parse a git repo', () => {
Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/getLambdaSourceCodeBucketName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
CloudFormationClient,
DescribeStacksCommand,
} from '@aws-sdk/client-cloudformation'
import { SOURCECODE_STACK_NAME } from '../stacks/stackName'
import { SOURCECODE_STACK_NAME } from '../stacks/stackName.js'

const cf = new CloudFormationClient({})

Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/getStackContexts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SSMClient } from '@aws-sdk/client-ssm'
import { getSettings } from '../../util/settings'
import { getSettings } from '../../util/settings.js'

type StackContexts = {
unwiredlabs: '0' | '1'
Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/iotRuleSqlCheckIfDefinedAndNotZero.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { iotRuleSqlCheckIfDefinedAndNotZero } from './iotRuleSqlCheckIfDefinedAndNotZero'
import { iotRuleSqlCheckIfDefinedAndNotZero } from './iotRuleSqlCheckIfDefinedAndNotZero.js'

describe('iotRuleSqlCheckIfDefinedAndNotZero', () => {
it('should check for undefined for the given values', () =>
Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/iotRuleSqlCheckUndefined.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { iotRuleSqlCheckUndefined } from './iotRuleSqlCheckUndefined'
import { iotRuleSqlCheckUndefined } from './iotRuleSqlCheckUndefined.js'

describe('iotRuleSqlCheckUndefined', () => {
it('should check for undefined for the given values', () =>
Expand Down
2 changes: 1 addition & 1 deletion cdk/helper/note.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk'
import chalk from 'chalk'

export const warn = (category: string, note: string): void => {
console.warn('', chalk.magenta('ℹ'), chalk.cyan(category), chalk.grey(note))
Expand Down
16 changes: 8 additions & 8 deletions cdk/resources/AGPSDeviceRequestHandler.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as CloudFormation from 'aws-cdk-lib'
import { Duration } from 'aws-cdk-lib'
import * as IAM from 'aws-cdk-lib/aws-iam'
import * as IoT from 'aws-cdk-lib/aws-iot'
import { iotRuleSqlCheckUndefined } from '../helper/iotRuleSqlCheckUndefined'
import * as SQS from 'aws-cdk-lib/aws-sqs'
import { Duration } from 'aws-cdk-lib'
import { LambdasWithLayer } from './LambdasWithLayer'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas'
import * as Lambda from 'aws-cdk-lib/aws-lambda'
import { LambdaLogGroup } from './LambdaLogGroup'
import { AGPSResolver } from './AGPSResolver'
import { AGPSStorage } from './AGPSStorage'
import * as SQS from 'aws-cdk-lib/aws-sqs'
import { iotRuleSqlCheckUndefined } from '../helper/iotRuleSqlCheckUndefined.js'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas.js'
import { AGPSResolver } from './AGPSResolver.js'
import { AGPSStorage } from './AGPSStorage.js'
import { LambdaLogGroup } from './LambdaLogGroup.js'
import { LambdasWithLayer } from './LambdasWithLayer.js'

export const MAX_RESOLUTION_TIME_IN_MINUTES = 10

Expand Down
16 changes: 8 additions & 8 deletions cdk/resources/AGPSResolver.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as CloudFormation from 'aws-cdk-lib'
import * as IAM from 'aws-cdk-lib/aws-iam'
import * as Lambda from 'aws-cdk-lib/aws-lambda'
import * as StepFunctions from 'aws-cdk-lib/aws-stepfunctions'
import * as StepFunctionTasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
import * as Lambda from 'aws-cdk-lib/aws-lambda'
import { LambdaLogGroup } from './LambdaLogGroup'
import { LambdasWithLayer } from './LambdasWithLayer'
import { CORE_STACK_NAME } from '../stacks/stackName'
import { enabledInContext } from '../helper/enabledInContext'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas'
import { AGPSStorage } from './AGPSStorage'
import { logToCloudWatch } from './logToCloudWatch'
import { enabledInContext } from '../helper/enabledInContext.js'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas.js'
import { CORE_STACK_NAME } from '../stacks/stackName.js'
import { AGPSStorage } from './AGPSStorage.js'
import { LambdaLogGroup } from './LambdaLogGroup.js'
import { LambdasWithLayer } from './LambdasWithLayer.js'
import { logToCloudWatch } from './logToCloudWatch.js'

/**
* Provides a state machine that can resolve A-GPS requests
Expand Down
18 changes: 9 additions & 9 deletions cdk/resources/CellGeolocation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as CloudFormation from 'aws-cdk-lib'
import * as IAM from 'aws-cdk-lib/aws-iam'
import * as DynamoDB from 'aws-cdk-lib/aws-dynamodb'
import * as IAM from 'aws-cdk-lib/aws-iam'
import * as Lambda from 'aws-cdk-lib/aws-lambda'
import * as StepFunctions from 'aws-cdk-lib/aws-stepfunctions'
import * as StepFunctionTasks from 'aws-cdk-lib/aws-stepfunctions-tasks'
import * as Lambda from 'aws-cdk-lib/aws-lambda'
import { logToCloudWatch } from './logToCloudWatch'
import { LambdaLogGroup } from './LambdaLogGroup'
import { LambdasWithLayer } from './LambdasWithLayer'
import { CORE_STACK_NAME } from '../stacks/stackName'
import { enabledInContext } from '../helper/enabledInContext'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas'
import { DeviceCellGeolocations } from './DeviceCellGeolocations'
import { enabledInContext } from '../helper/enabledInContext.js'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas.js'
import { CORE_STACK_NAME } from '../stacks/stackName.js'
import { DeviceCellGeolocations } from './DeviceCellGeolocations.js'
import { LambdaLogGroup } from './LambdaLogGroup.js'
import { LambdasWithLayer } from './LambdasWithLayer.js'
import { logToCloudWatch } from './logToCloudWatch.js'

/**
* Describes the step functions which resolves the geolocation of LTE/NB-IoT network cells using third-party location providers
Expand Down
14 changes: 7 additions & 7 deletions cdk/resources/CellGeolocationApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as CloudFormation from 'aws-cdk-lib'
import * as HttpApi from 'aws-cdk-lib/aws-apigatewayv2'
import * as IAM from 'aws-cdk-lib/aws-iam'
import * as Lambda from 'aws-cdk-lib/aws-lambda'
import * as SQS from 'aws-cdk-lib/aws-sqs'
import { logToCloudWatch } from './logToCloudWatch'
import { CellGeolocation } from './CellGeolocation'
import { LambdasWithLayer } from './LambdasWithLayer'
import * as CloudWatchLogs from 'aws-cdk-lib/aws-logs'
import { LambdaLogGroup } from './LambdaLogGroup'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas'
import { DeviceCellGeolocations } from './DeviceCellGeolocations'
import * as SQS from 'aws-cdk-lib/aws-sqs'
import { AssetTrackerLambdas } from '../stacks/AssetTracker/lambdas.js'
import { CellGeolocation } from './CellGeolocation.js'
import { DeviceCellGeolocations } from './DeviceCellGeolocations.js'
import { LambdaLogGroup } from './LambdaLogGroup.js'
import { LambdasWithLayer } from './LambdasWithLayer.js'
import { logToCloudWatch } from './logToCloudWatch.js'

/**
* Allows to resolve cell geolocations using a HTTP API
Expand Down
4 changes: 2 additions & 2 deletions cdk/resources/FirmwareCI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as CloudFormation from 'aws-cdk-lib'
import * as S3 from 'aws-cdk-lib/aws-s3'
import { CORE_STACK_NAME, FIRMWARE_CI_STACK_NAME } from '../stacks/stackName'
import * as IAM from 'aws-cdk-lib/aws-iam'
import * as S3 from 'aws-cdk-lib/aws-s3'
import { CORE_STACK_NAME, FIRMWARE_CI_STACK_NAME } from '../stacks/stackName.js'

export class FirmwareCI extends CloudFormation.Resource {
public readonly bucket
Expand Down
Loading

0 comments on commit 90d01a0

Please sign in to comment.