Skip to content

Commit

Permalink
Modularize SDK client
Browse files Browse the repository at this point in the history
Previously, there was no way for users to create new instances of
`SindriClient` because both the logger and the internal generated API client
operated on a global level. This updates all of that so that instances are
fully independent, and adds a `SindriClient.create()` method to initialize new
client instances. These can use different credentials, have a different log
level, etc.

As part of the modularization, I configured openapi-typescript-codegen to use a
persistent `request.ts` module that we can customize. This allows our special
handling of `FormData` to live outside of the code that gets clobbered with
each regeneration. I also hacked in a `logger` field in the `OpenAPIConfig`
class which `request.ts` uses to add debug logging around all API
requests/responses.

I made significant progress on getting the CLI to use the client consistently.
All of the commands use it for all logging and requests now, but we still have
two parallel implementations of the packaging and polling for circuit
deployment so that's a significant last piece that still needs to be addressed.
Because the client requests are now logged internally, I was able to remove all
of that explicit logging from the CLI commands. This means there's no longer
the fancy logic around not logging repeated poll responses if the status hasn't
changed, but I think it's worth it to have the request logging be more uniform
and universal.

Making these changes required regenerating the internal API client, so this
pulls in miscellaneous backend API changes that have taken place. Nothing
particularly major, adding `noir_version` to Noir circuit responses is one
example, but these are mixed in here.

Connects #60
Closes #58
Closes #70
Merges #73
  • Loading branch information
sangaline authored Feb 22, 2024
1 parent 9abae31 commit 52216e9
Show file tree
Hide file tree
Showing 33 changed files with 736 additions and 505 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"download-sindri-manifest-schema": "nwget https://sindri.app/api/v1/sindri-manifest-schema.json -O sindri-manifest.json && prettier --write sindri-manifest.json",
"download-sindri-manifest-schema:dev": "nwget http://localhost/api/v1/sindri-manifest-schema.json -O sindri-manifest.json && prettier --write sindri-manifest.json",
"download-sindri-manifest-schema:docker": "nwget http://host.docker.internal/api/v1/sindri-manifest-schema.json -O sindri-manifest.json && prettier --write sindri-manifest.json",
"generate-api": "rm -rf src/lib/api/ && openapi --client axios --input https://sindri.app/api/openapi.json --output src/lib/api/ --useUnionTypes && prettier --write src/lib/api/**/*",
"generate-api:dev": "rm -rf src/lib/api/ && openapi --client axios --input http://localhost/api/openapi.json --output src/lib/api/ --useUnionTypes && prettier --write src/lib/api/**/*",
"generate-api:docker": "rm -rf src/lib/api/ && openapi --client axios --input http://host.docker.internal/api/openapi.json --output src/lib/api/ --useUnionTypes && prettier --write src/lib/api/**/*",
"generate-api": "mv src/lib/api/core/request.ts tmp-request.ts && rm -rf src/lib/api/ && openapi --client axios --input https://sindri.app/api/openapi.json --name ApiClient --output src/lib/api/ --request tmp-request.ts --useUnionTypes && rm tmp-request.ts && prettier --write src/lib/api/**/*",
"generate-api:dev": "mv src/lib/api/core/request.ts tmp-request.ts && rm -rf src/lib/api/ && openapi --client axios --input http://localhost/api/openapi.json --name ApiClient --output src/lib/api/ --request tmp-request.ts --useUnionTypes && rm tmp-request.ts && prettier --write src/lib/api/**/*",
"generate-api:docker": "mv src/lib/api/core/request.ts tmp-request.ts && rm -rf src/lib/api/ && openapi --client axios --input http://host.docker.internal/api/openapi.json --name ApiClient --output src/lib/api/ --request tmp-request.ts --useUnionTypes && rm tmp-request.ts && prettier --write src/lib/api/**/*",
"lint": "eslint '**/*.{js,ts}'",
"format": "prettier --write '**/*.{js,json,md,ts}'",
"test": "yarn build && yarn test:fast",
Expand Down
Loading

0 comments on commit 52216e9

Please sign in to comment.