Skip to content

Commit

Permalink
Merge branch 'jul/typescript-5' into 'master'
Browse files Browse the repository at this point in the history
Upgrade to typescript 5

See merge request TankerHQ/sdk-js!993
  • Loading branch information
JMounier committed Nov 22, 2023
2 parents 102c2fd + 88dc2a4 commit 934e1d7
Show file tree
Hide file tree
Showing 38 changed files with 1,846 additions and 1,748 deletions.
161 changes: 98 additions & 63 deletions config/tsconfig.base.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/tsconfig.browser.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"module": "CommonJS",
"verbatimModuleSyntax": false,
"importHelpers": true,
"downlevelIteration": true,
"lib": ["DOM", "WebWorker"],
Expand Down
4 changes: 2 additions & 2 deletions config/tsconfig.es.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "es2019",
"module": "commonjs",
"module": "CommonJS",
"verbatimModuleSyntax": false
},
"exclude": [
"../**/__tests__/*",
Expand Down
2 changes: 1 addition & 1 deletion config/tsconfig.node.dom.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.node.json",
"compilerOptions": {
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string", "DOM"],
"lib": ["ES2023", "DOM"],
},
"files": [], // "files" MUST be kept empty. This is a _meta_ tsconfig and should not generate anything by itself.
}
8 changes: 4 additions & 4 deletions config/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
// Recommended values for Node 12: https://github.com/tsconfig/bases/blob/main/bases/node12.json
"target": "es2019",
"module": "commonjs",
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string"],
"module": "CommonJS",
"verbatimModuleSyntax": false,
// Recommended values for Node 18: https://github.com/tsconfig/bases/blob/main/bases/node18.json
"lib": ["ES2023"],
},
"exclude": [
"../**/__tests__/*",
Expand Down
2 changes: 1 addition & 1 deletion config/tsconfig.node.web.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.node.dom.json",
"compilerOptions": {
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string", "DOM", "WebWorker"],
"lib": ["ES2023", "DOM", "WebWorker"],
},
"files": [], // "files" MUST be kept empty. This is a _meta_ tsconfig and should not generate anything by itself.
}
1 change: 1 addition & 0 deletions config/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const getLoaders = (env) => {
const tsLoaderCompilerOptions = {
target: 'es2019',
declaration: false,
declarationMap:false,
sourceMap: false,
declarationDir: undefined,
composite: false,
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.18",
"@types/sinon": "^10.0.13",
"@types/webpack": "^5.28.0",
"@types/webpack-env": "^1.18.0",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"@types/webpack": "^5.28.5",
"@types/webpack-env": "^1.18.4",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"buffer": "6.0.3",
"eslint": "8.36.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-plugin-chai-expect": "3.0.0",
"eslint-plugin-chai-friendly": "0.7.2",
"eslint-plugin-compat": "4.0.2",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-compat": "4.2.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-mocha-no-only": "1.1.1",
"karma": "6.4.1",
"karma-browserstack-launcher": "1.6.0",
Expand All @@ -83,10 +83,10 @@
"ts-loader": "~9.4.2",
"ts-node": "~10.9.1",
"tsconfig-paths": "^4.1.2",
"typescript": "~4.9.4",
"typescript": "~5.2.2",
"util": "^0.12.5",
"webpack": "5.76.1",
"webpack-cli": "^5.0.1"
"webpack": "5.84.0",
"webpack-cli": "^5.1.4"
},
"workspaces": [
"packages/*",
Expand All @@ -96,7 +96,7 @@
"browserslist": [
"last 2 versions",
"Firefox ESR",
"node >= 14",
"node >= 18",
"not IE 11",
"not dead"
],
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Blocks/__tests__/payloads.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ready as cryptoReady, tcrypto, random } from '@tanker/crypto';
import { expect } from '@tanker/test-utils';
import { UpgradeRequired } from '@tanker/errors';
import { Block, serializeBlock, unserializeBlock } from '../payloads';
import { preferredNature, NATURE_KIND, Nature } from '../Nature';
import { type Block, serializeBlock, unserializeBlock } from '../payloads';
import { preferredNature, NATURE_KIND, type Nature } from '../Nature';

describe('blocks: payloads', () => {
before(() => cryptoReady);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/DataProtection/EncryptionSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Resource } from './types';
export class EncryptionSession {
_dataProtector: DataProtector;
_resource: Resource;
_paddingStep?: number | Padding;
_paddingStep: number | Padding | undefined;
_getStatus: () => Status;

constructor(dataProtector: DataProtector, getStatus: () => Status, resource: Resource, paddingStep?: number | Padding) {
Expand Down
18 changes: 6 additions & 12 deletions packages/core/src/DataProtection/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type EncryptionOptions = {
shareWithUsers?: Array<b64string>;
shareWithGroups?: Array<string>;
shareWithSelf?: boolean;
paddingStep?: number | Padding;
paddingStep?: number | Padding | undefined;
};

export type SharingOptions = { shareWithUsers?: Array<b64string>; shareWithGroups?: Array<string>; };
Expand All @@ -37,7 +37,7 @@ export const extractSharingOptions = (options: Record<string, unknown>, error: u

(['shareWithUsers', 'shareWithGroups'] as const).forEach(key => {
if (key in options) {
const array: Array<string> = options[key];
const array = options[key];
if (!(array instanceof Array))
throw error;
array.forEach(el => assertNotEmptyString(el, `options.${key}`));
Expand All @@ -54,14 +54,8 @@ export const extractSharingOptions = (options: Record<string, unknown>, error: u
);
}

if (options['shareWithUsers']) {
for (const identity of options['shareWithUsers']) {
assertNotEmptyString(identity, 'options.shareWithUsers');
}
}

if (options['shareWithGroups']) {
for (const groupId of options['shareWithGroups']) {
if (sharingOptions.shareWithGroups) {
for (const groupId of sharingOptions.shareWithGroups) {
utils.assertB64StringWithSize(groupId, 'options.shareWithGroups', tcrypto.SIGNATURE_PUBLIC_KEY_SIZE);
}
}
Expand Down Expand Up @@ -137,14 +131,14 @@ export const extractResourceMetadata = (options: Record<string, unknown>, input?
return resourceMetadata;
};

export const extractOutputOptions = <T extends Data>(options: Record<string, unknown>, input?: Data): OutputOptions<T> => {
export const extractOutputOptions = <T extends Data>(options: Record<string, unknown>, input?: T): OutputOptions<T> => {
if (!isObject(options))
throw new InvalidArgument('options', '{ type: Class<T>, mime?: string, name?: string, lastModified?: number }', options);

let outputType;

if (options['type']) {
outputType = options['type'];
outputType = options['type'] as Class<T>;
} else if (input) {
outputType = getConstructor(input);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Groups/Serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InternalError } from '@tanker/errors';

import type { PublicProvisionalUser } from '../Identity';
import { getStaticArray, unserializeGeneric, unserializeGenericSub, unserializeList, encodeListLength, encodeUint32 } from '../Blocks/Serialize';
import { BlockNoMetadata, unserializeBlock } from '../Blocks/payloads';
import { type BlockNoMetadata, unserializeBlock } from '../Blocks/payloads';
import type { VerificationFields } from '../Blocks/Block';
import { hashBlock } from '../Blocks/Block';
import { preferredNature, NATURE_KIND, NATURE } from '../Blocks/Nature';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Groups/__tests__/Serialize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
unserializeUserGroupAdditionV3,
serializeUserGroupRemoval,
unserializeUserGroupRemoval,
UserGroupCreationRecordV1,
type UserGroupCreationRecordV1,
} from '../Serialize';

describe('groups blocks', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Identity/__tests__/identity.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { b64string, generichash, ready as cryptoReady, utils } from '@tanker/crypto';
import { type b64string, generichash, ready as cryptoReady, utils } from '@tanker/crypto';
import { InvalidArgument } from '@tanker/errors';
import { expect } from '@tanker/test-utils';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Identity/__tests__/userSecret.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { b64string, ready as cryptoReady, utils } from '@tanker/crypto';
import { type b64string, ready as cryptoReady, utils } from '@tanker/crypto';
import { expect } from '@tanker/test-utils';
import { obfuscateUserId, createUserSecretBinary } from '@tanker/identity';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/LocalUser/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
formatVerificationRequest,
isPreverifiedVerificationRequest,
formatVerificationsRequest,
SetVerificationMethodRequest,
type SetVerificationMethodRequest,
} from './requests';
import type {
VerificationMethod,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/LocalUser/SessionCertificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import varint from 'varint';
import type { VerificationMethod, VerificationWithToken } from './types';
import { isPreverifiedVerification, isPreverifiedVerificationMethod } from './types';
import { getStaticArray, unserializeGeneric } from '../Blocks/Serialize';
import { Nature, NATURE_KIND, preferredNature } from '../Blocks/Nature';
import { type Nature, NATURE_KIND, preferredNature } from '../Blocks/Nature';

export const enum VerificationMethodTypes {
email = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('SessionCertificate', () => {
it('should throw when serializing an invalid SessionCertificate', async () => {
const badSessionCertificate: SessionCertificateRecord = {
timestamp: Math.floor(Date.now() / 1000),
verification_method_type: 999,
verification_method_type: 999 as VerificationMethodTypes,
verification_method_target: new Uint8Array(0),
session_public_signature_key: new Uint8Array(0),
};
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/LocalUser/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RemoteVerification, RemoteVerificationWithToken, PreverifiedVerifi
import type { SecretProvisionalIdentity } from '../Identity';
import type { SignedChallenge } from '../OidcNonce/types';

type WithToken<T> = T & { with_token?: { nonce: string; } };
type WithToken<T> = T & { with_token?: { nonce: string; } | undefined };
type WithVerificationCode<T> = WithToken<T> & { verification_code: string; };
type Preverified<T> = T & { is_preverified: true };

Expand All @@ -21,13 +21,13 @@ type OidcRequest = {
oidc_id_token: string;
oidc_challenge: b64string;
oidc_challenge_signature: b64string;
oidc_test_nonce?: string;
oidc_test_nonce: string | undefined;
};
type PhoneNumberRequest = {
phone_number: string;
encrypted_phone_number: Uint8Array;
user_salt: Uint8Array;
provisional_salt?: Uint8Array;
provisional_salt: Uint8Array | undefined;
};
type E2ePassphraseRequest = {
hashed_e2e_passphrase: Uint8Array;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/OidcNonce/__tests__/OidcStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { b64string, ready as cryptoReady, tcrypto, utils } from '@tanker/crypto';
import { type b64string, ready as cryptoReady, tcrypto, utils } from '@tanker/crypto';
import { InternalError } from '@tanker/errors';
import { expect } from '@tanker/test-utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ProvisionalIdentity/Serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { preferredNature, NATURE_KIND } from '../Blocks/Nature';
import type { VerificationFields } from '../Blocks/Block';
import { hashBlock } from '../Blocks/Block';
import { getStaticArray, unserializeGeneric } from '../Blocks/Serialize';
import { BlockNoMetadata, unserializeBlock } from '../Blocks/payloads';
import { type BlockNoMetadata, unserializeBlock } from '../Blocks/payloads';
import type { ProvisionalUserKeys } from '../Identity';

export type ProvisionalIdentityClaimRecord = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Resources/Serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { tcrypto, utils } from '@tanker/crypto';

import type { PublicProvisionalUser } from '../Identity';
import { getStaticArray, unserializeGeneric } from '../Blocks/Serialize';
import { BlockNoMetadata, unserializeBlock } from '../Blocks/payloads';
import { type BlockNoMetadata, unserializeBlock } from '../Blocks/payloads';
import { preferredNature, NATURE_KIND, NATURE } from '../Blocks/Nature';
import type { NatureKind, Nature } from '../Blocks/Nature';

Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/Tanker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import { LocalUserManager } from './LocalUser/Manager';
import type { DataStoreOptions } from './Session/Storage';

import {
assertVerifications,
assertVerification,
assertVerificationOptions,
isPreverifiedVerification,
countPreverifiedVerifications,
} from './LocalUser/types';
import type {
Verification,
EmailVerification,
RemoteVerification,
Expand All @@ -21,11 +28,6 @@ import {
PhoneNumberVerification,
LegacyEmailVerificationMethod,
PreverifiedVerification,
assertVerifications,
assertVerification,
assertVerificationOptions,
isPreverifiedVerification,
countPreverifiedVerifications,
} from './LocalUser/types';
import { extractUserData } from './LocalUser/UserData';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/TestGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { KeyPublishEntry } from '../Resources/Serialize';
import { getKeyPublishEntryFromBlock, makeKeyPublish, makeKeyPublishToProvisionalUser } from '../Resources/Serialize';

import { hashBlock, createBlock } from '../Blocks/Block';
import { Block, serializeBlock } from '../Blocks/payloads';
import { type Block, serializeBlock } from '../Blocks/payloads';
import { NATURE_KIND, preferredNature } from '../Blocks/Nature';

import type { User, Device } from '../Users/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/errors.internal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class InvalidBlockError extends Error {
nature: string;
args?: Record<string, unknown>;
args: Record<string, unknown> | undefined;

constructor(nature: string, message: string, e?: Record<string, unknown>) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ResizerStream, Transform } from '@tanker/stream-base';
import type { TransformCallback, WriteCallback } from '@tanker/stream-base';

import type { KeyMapper } from './KeyMapper';
import { extractEncryptionFormat, SimpleEncryptor } from './EncryptionFormats';
import { extractEncryptionFormat, type SimpleEncryptor } from './EncryptionFormats';

export class DecryptionStreamSimple extends Transform {
_mapper: KeyMapper;
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/PaddingStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { paddedFromClearSize } from './padding';
export class PadStream extends Transform {
_clearChunkSize: number;
_paddedChunkSize: number;
_paddingStep?: number | Padding;
_paddingStep: number | Padding | undefined;
_bytesProcessed: number;
_paddingLeft: number | null;
_lastChunkSize: number;
Expand Down
6 changes: 3 additions & 3 deletions packages/crypto/src/padding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export const paddedFromClearSize = (clearSize: number, paddingStep?: number | Pa
return Math.max(padme(clearSize), minimalPadding) + 1;
}

if (paddingStep < 1) {
const actualPaddingStep = paddingStep !== Padding.OFF ? paddingStep : 1;

if (actualPaddingStep < 1) {
throw new InternalError('assertion error: paddingStep should be greater or equal to 1');
}

const actualPaddingStep = paddingStep !== Padding.OFF ? paddingStep : 1;

// Round 0 up to paddingStep (plus the padding byte)
if (clearSize === 0) {
return actualPaddingStep + 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore/base/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class DataStoreError extends Error {
next?: Error | null;
next: Error | null | undefined;
override name: string;

constructor(name: string, error?: Error | null, messageArg?: string) {
Expand Down
12 changes: 6 additions & 6 deletions packages/errors/src/ErrorInfo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export type ErrorMessage = string;
export type ApiError = {
apiCode?: string;
apiMethod?: string;
apiRoute?: string;
httpStatus?: number;
message?: string;
traceId?: string;
apiCode?: string | undefined;
apiMethod?: string | undefined;
apiRoute?: string | undefined;
httpStatus?: number | undefined;
message?: string | undefined;
traceId?: string | undefined;
};
export type ErrorInfo = ErrorMessage | ApiError;
Loading

0 comments on commit 934e1d7

Please sign in to comment.