Skip to content

Conversation

@smartyandrewb
Copy link
Contributor

@smartyandrewb smartyandrewb requested a review from camiblanch July 22, 2025 17:24
const SharedCredentials = require("./SharedCredentials");
let SharedCredentials;
try {
SharedCredentials = require("../dist/cjs/SharedCredentials.cjs").default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is going to work for production level stuff. None of the code in src should reference the code in dist. It seems like we are trying to get things to work in our uncompiled code with both commonjs and esmodules.

I think it's more meant that the uncompiled code should all be one or the other. I'm not sure if things are playing nicely with the hybrid solution we have. I think we need to migrate completely to esmodules to avoid having to do stuff like you are here. What do you think?

Otherwise we could maybe update our tests to all run on compiled code only? I'm not sure if that's the conventional way of doing things though

@@ -0,0 +1,24 @@
import { expect } from "chai";
import * as SmartySDK from "../dist/esm/index.mjs";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't love that we are referencing files from the /dist/ directory in the tests. We should be able to setup the tests to run on the non bundled code. I think the only exception we've made is in the tests/test_ExtractExample.js file because it helps us to test that our esm translation/bundling happens correctly. If we can avoid doing it in other places that would be great.

I think an additional task outside of this project could be to refactor the tests so there's a test specifically written for testing that esm translation/bundling is happening correctly instead of having it as part of the extract tests

const expect = chai.expect;
const RetrySender = require("../src/RetrySender");
const {MockSenderWithStatusCodesAndHeaders} = require("./fixtures/mock_senders");
const RetrySender = require("../dist/cjs/RetrySender.cjs").default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, can we convert this test file to typescript like you did with a bunch of the other tests? Then you can use import instead of require here and avoid referencing the /dist directory


it("test backoff does not exceed max", async function () {
let inner = new MockSenderWithStatusCodesAndHeaders(["500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "500", "200"]);
let inner = new MockSenderWithStatusCodesAndHeaders([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change due to prettier? Maybe we should add the prettier config to this repo as well so we don't just go with the default prettier settings?

tsconfig.json Outdated
"types": ["mocha", "chai", "node"]
},
"include": ["src/**/*"],
"include": ["src/**/*", "tests/**/*.ts"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super well versed in how the tsconfig.json should be setup, but I'm wondering if this could be simplified to include all test files like we do for the src files? So instead of *.ts change it to *?

let request;
let urlOverride;
let baseUrlSender;
let innerSender: Sender;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice capturing these common types

index.mjs Outdated
SharedCredentials,
StaticCredentials,
Errors,
AgentSender,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the AgentSender and Request classes should be exposed as part of the core. Our end users shouldn't be calling those directly so they shouldn't be included in core.

import AgentSender from "../src/AgentSender.js";
import Request from "../src/Request.js";
import Response from "../src/Response.js";
import { Sender } from "../src/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { Sender } from "../src/types.js";
import { Sender } from "../src/types";

Since it's a typescript file, you can omit the extension according to the tsconfig

import BaseUrlSender from "../src/BaseUrlSender.js";
import Request from "../src/Request.js";
import Response from "../src/Response.js";
import { Sender } from "../src/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { Sender } from "../src/types.js";
import { Sender } from "../src/types";

import CustomHeaderSender from "../src/CustomHeaderSender.js";
import Request from "../src/Request.js";
import Response from "../src/Response.js";
import { Sender } from "../src/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { Sender } from "../src/types.js";
import { Sender } from "../src/types";

import { MockSenderWithStatusCodesAndHeaders } from "./fixtures/mock_senders.js";
import Request from "../src/Request.js";
import Response from "../src/Response.js";
import type { Sender, Sleeper, MockSenderInstance, MockSleeperInstance } from "../src/types.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import type { Sender, Sleeper, MockSenderInstance, MockSleeperInstance } from "../src/types.js";
import type { Sender, Sleeper, MockSenderInstance, MockSleeperInstance } from "../src/types";

import SigningSender from "../src/SigningSender.js";
import StaticCredentials from "../src/StaticCredentials.js";
import SharedCredentials from "../src/SharedCredentials.js";
import { UnprocessableEntityError } from "../src/Errors.js";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { UnprocessableEntityError } from "../src/Errors.js";
import { UnprocessableEntityError } from "../src/Errors";

src/types.ts Outdated
}

export interface Response {
statusCode: string | number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be always a number instead of sometimes a string?

Copy link
Contributor

@camiblanch camiblanch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@smartyandrewb smartyandrewb merged commit fad7794 into master Aug 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants