Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK import by module #431

Closed
wants to merge 13 commits into from
Closed
2 changes: 1 addition & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
npx nx affected --target test:e2e \
--exclude tag:type:application \
--base=origin/main \
--testPathIgnorePatterns=packages/armory-sdk/src/lib/__test__/e2e/user-journeys.spec.ts
--testPathIgnorePatterns=packages/armory-sdk/src/__test__/e2e/user-journeys.spec.ts

- name: Send Slack notification on failure
if: failure() && github.ref == 'refs/heads/main'
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ setup:

# === Packages ===

# - Uses `--skip-publish` option because the publish step is done in the CI.
# - Uses `--fist-release` option to avoid generating a tag.
# - Runs `npm install` after to properly update the `package-lock.json` with
# the new version.
packages/release:
npx nx release --skip-publish
npx nx release --skip-publish --first-release
npm install

# TODO: The default override for `dependsOn` of `nx-release-publish` is not
# working. Ideally, the release target should depend on package's build.
Expand Down
3 changes: 2 additions & 1 deletion apps/devtool/src/app/_components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { faArrowsRotate, faFileSignature } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { AuthorizationResponse, Evaluate, SendEvaluationResponse, SignatureRequest } from '@narval/armory-sdk'
import { AuthorizationResponse, SendEvaluationResponse, SignatureRequest } from '@narval/armory-sdk'
import { Evaluate } from '@narval/armory-sdk/auth'
import { AuthorizationRequest, EvaluationRequest, hexSchema, stringify } from '@narval/policy-engine-shared'
import { FC, ReactNode, useEffect, useState } from 'react'
import NarButton from '../_design-system/NarButton'
Expand Down
11 changes: 4 additions & 7 deletions apps/devtool/src/app/_hooks/useAuthServerApi.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
AuthAdminClient,
AuthClient,
AuthorizationRequestStatus,
EntityStoreClient,
Evaluate
} from '@narval/armory-sdk'
import { AuthorizationRequestStatus } from '@narval/armory-sdk'
import { AuthAdminClient, AuthClient, Evaluate } from '@narval/armory-sdk/auth'
import { EntityStoreClient } from '@narval/armory-sdk/data-store'

import { SigningAlg } from '@narval/signature'
import { useMemo, useState } from 'react'
import { extractErrorMessage, getUrlProtocol } from '../_lib/utils'
Expand Down
2 changes: 1 addition & 1 deletion apps/devtool/src/app/_hooks/useDataStoreApi.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityStoreClient, PolicyStoreClient } from '@narval/armory-sdk'
import { EntityStoreClient, PolicyStoreClient } from '@narval/armory-sdk/data-store'
import {
Entities,
EntityData,
Expand Down
5 changes: 2 additions & 3 deletions apps/devtool/src/app/_hooks/useVaultApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import {
DeriveAccountRequest,
GenerateKeyRequest,
ImportPrivateKeyRequest,
ImportSeedRequest,
VaultAdminClient,
VaultClient
ImportSeedRequest
} from '@narval/armory-sdk'
import { VaultAdminClient, VaultClient } from '@narval/armory-sdk/vault'
import { Request } from '@narval/policy-engine-shared'
import { Alg, Jwk, RsaPublicKey, SigningAlg, rsaKeyToKid, rsaPublicKeySchema } from '@narval/signature'
import { exportJWK, importSPKI } from 'jose'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faPlus } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { CreateAuthClientResponse } from '@narval/armory-sdk'
import { CreateAuthClientResponse } from '@narval/armory-sdk/auth'
import { useEffect, useState } from 'react'
import { v4 as uuid } from 'uuid'
import ValueWithCopy from '../../../_components/ValueWithCopy'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { faPlus } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { CreateVaultClientResponse } from '@narval/armory-sdk'
import { CreateVaultClientResponse } from '@narval/armory-sdk/vault'
import { useEffect, useState } from 'react'
import { v4 as uuid } from 'uuid'
import ValueWithCopy from '../../../_components/ValueWithCopy'
Expand Down
7 changes: 4 additions & 3 deletions examples/gas-station/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable no-console */

import { AuthClient } from '@narval/armory-sdk/auth'
import { AuthorizationRequestStatus } from '@narval/armory-sdk/types'
import { VaultClient } from '@narval/armory-sdk/vault'

import {
AuthClient,
AuthorizationRequestStatus,
EntityType,
JwtString,
Policy,
Expand All @@ -11,7 +13,6 @@ import {
SigningAlg,
UserRole,
ValueOperators,
VaultClient,
buildSignerEip191,
jwkSchema,
polling,
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@typescript-eslint/parser": "7.9.0",
"autoprefixer": "10.4.19",
"babel-jest": "29.7.0",
"dotenv": "16.4.5",
"dotenv-cli": "7.3.0",
"eslint": "8.57.0",
"eslint-config-next": "14.2.3",
Expand Down Expand Up @@ -108,6 +107,7 @@
"class-validator": "0.14.1",
"clsx": "2.1.1",
"date-fns": "3.6.0",
"dotenv": "16.4.5",
"express": "4.19.2",
"handlebars": "4.7.8",
"jose": "5.5.0",
Expand Down
16 changes: 14 additions & 2 deletions packages/armory-sdk/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
ARMORY_SDK_PROJECT_NAME := armory-sdk
ARMORY_SDK_PROJECT_DIR := ./packages/armory-sdk
ARMORY_SDK_DIST_DIR := ./dist/packages/armory-sdk

# === Build ===

armory-sdk/build:
npx nx build ${ARMORY_SDK_PROJECT_NAME}
@# This is a workaround to achieve importing modules by path like
@# `@narval-xyz/armory-sdk/vault` or `@narval-xyz/armory-sdk/data-source` to
@# avoid name clashing.
@# For some reason, @wcalderipe couldn't make it work with the NX release
@# build system when the option `external` is set to `none`. As a reminder,
@# the `external` option is a crucial step in the build process to bundle the
@# `signature` and `policy-engine-shared` into the SDK artifact.
mv ${ARMORY_SDK_DIST_DIR}/src/* ${ARMORY_SDK_DIST_DIR}
@# Delete the packages directory because it's not used by any built code and
@# it increases the bundle size.
rm -rf ${ARMORY_SDK_DIST_DIR}/{src,packages,__test__}

# === Code format ===

Expand Down Expand Up @@ -60,10 +72,10 @@ armory-sdk/generate/-http-client:

armory-sdk/generate/auth-client:
INPUT_SPEC=http://localhost:3005/docs-yaml \
OUTPUT_DIR=packages/armory-sdk/src/lib/http/client/auth \
OUTPUT_DIR=packages/armory-sdk/src/http/client/auth \
make armory-sdk/generate/-http-client

armory-sdk/generate/vault-client:
INPUT_SPEC=http://localhost:3011/docs-yaml \
OUTPUT_DIR=packages/armory-sdk/src/lib/http/client/vault \
OUTPUT_DIR=packages/armory-sdk/src/http/client/vault \
make armory-sdk/generate/-http-client
2 changes: 1 addition & 1 deletion packages/armory-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@narval-xyz/armory-sdk",
"version": "0.4.1",
"version": "0.5.0",
"license": "MPL-2.0",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Action, EvaluationRequest, FIXTURE, Request, TransactionRequest } from '@narval/policy-engine-shared'
import { Alg, Payload, hash, privateKeyToJwk, signJwt } from '@narval/signature'
import { UNSAFE_PRIVATE_KEY } from 'packages/policy-engine-shared/src/lib/dev.fixture'
import { v4 as uuid } from 'uuid'
import { toHex } from 'viem'

Expand All @@ -12,9 +11,9 @@ const sign = async (request: Request) => {
requestHash: message
}

const aliceSignature = await signJwt(payload, privateKeyToJwk(UNSAFE_PRIVATE_KEY.Alice, Alg.ES256K))
const bobSignature = await signJwt(payload, privateKeyToJwk(UNSAFE_PRIVATE_KEY.Bob, Alg.ES256K))
const carolSignature = await signJwt(payload, privateKeyToJwk(UNSAFE_PRIVATE_KEY.Carol, Alg.ES256K))
const aliceSignature = await signJwt(payload, privateKeyToJwk(FIXTURE.UNSAFE_PRIVATE_KEY.Alice, Alg.ES256K))
const bobSignature = await signJwt(payload, privateKeyToJwk(FIXTURE.UNSAFE_PRIVATE_KEY.Bob, Alg.ES256K))
const carolSignature = await signJwt(payload, privateKeyToJwk(FIXTURE.UNSAFE_PRIVATE_KEY.Carol, Alg.ES256K))

return { aliceSignature, bobSignature, carolSignature }
}
Expand Down
61 changes: 6 additions & 55 deletions packages/armory-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,7 @@
export * from './lib/auth'
export * from './lib/data-store'
export * from './lib/domain'
export * from './lib/http'
export * from './lib/sdk'
export * from './lib/shared/promise'
export * from './lib/types'
export * from './lib/vault'
export * from './domain'
export * from './http'
export * from './sdk'
export * from './shared/promise'
export * from './types'

export { resourceId } from './lib/utils'

export {
Alg,
PrivateKey,
PublicKey,
RsaPublicKey,
SigningAlg,
base64UrlToHex,
buildSignerEip191,
buildSignerForAlg,
eip191Hash,
getPublicKey,
hash,
hexToBase64Url,
jwkSchema,
privateKeyToJwk,
publicKeyToJwk,
signJwt
} from '@narval/signature'

export {
AccessToken,
AccountEntity,
AccountType,
Action,
Address,
CreateAuthorizationRequest,
Criterion,
Decision,
Eip712TypedData,
Entities,
EntityType,
EntityUtil,
Hex,
JwtString,
Policy,
PolicyCriterion,
Request,
Then,
TransactionRequest,
UserEntity,
UserRole,
ValueOperators,
getAddress,
toHex
} from '@narval/policy-engine-shared'
export { resourceId } from './utils'
File renamed without changes.
1 change: 1 addition & 0 deletions packages/armory-sdk/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"sourceMap": false,
"types": ["node"]
},
"include": ["src/**/*.ts"],
Expand Down
1 change: 1 addition & 0 deletions packages/policy-engine-shared/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"sourceMap": false,
"types": ["node"]
},
"include": ["src/**/*.ts"],
Expand Down
1 change: 1 addition & 0 deletions packages/signature/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"sourceMap": false,
"types": ["node"]
},
"include": ["src/**/*.ts"],
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"noImplicitThis": true,
"paths": {
"@narval/armory-sdk": ["packages/armory-sdk/src/index.ts"],
"@narval/armory-sdk/*": ["packages/armory-sdk/src/*"],
"@narval/config-module": ["packages/config-module/src/index.ts"],
"@narval/encryption-module": ["packages/encryption-module/src/index.ts"],
"@narval/nestjs-shared": ["packages/nestjs-shared/src/index.ts"],
Expand Down