DOCUMENTATION

SDK packages and SubApp integration

SSO, permissions, test identities, and quotas

Page updated 2026-12-05

SDK packages and SubApp integration

App versions and conversion

Register new Apps with Register a V2 App. Configure exact HTTPS callbacks, the commercial model, resource meters, custom product requirements and the Billing policy for storage. Keep the App-specific credential in Worker Secrets. Use Authorization Code with PKCE S256 and the app:session scope. Storage metering also requires verified service identity and the storage:meter scope.

Existing Apps remain Legacy until an administrator converts them. Adapt the SubApp SDK, callbacks, server-side refresh and Billing integration before opening Convert to V2. Review the advisory App Integration Check and the conversion preview. While Billing confirmation is pending, Legacy access and counters remain authoritative. Repair the dependency and retry the original command. After confirmation, the App remains V2. Configuration updates and V2-compatible code rollback remain available.

App IDs, user UUIDs, historical permissions and verified permanent entitlements survive conversion. A historical permission alone does not establish a paid entitlement. Billing authorizes V2 commercial access and meters usage. Verify ordinary sign-in, grandfathered access, session revocation and background renewal during each App cutover.

The seven packages use the private aryuki-dev GitHub Packages registry, https://npm.pkg.github.com. Pin Auth, Billing and Storage to 0.1.0-alpha.2. Pin the other four packages to 0.1.0-alpha.1.

PackageUseAryuki dependencies
@aryuki-dev/shared-typesBoth transports, session and storage types, HTTP errorsNone
@aryuki-dev/auth-sdkPKCE, grant exchange, refresh, revocation, Test Accessshared-types
@aryuki-dev/billing-sdkUsage, entitlements, storage metering, Checkout and Portalshared-types
@aryuki-dev/ai-sdkNon-streaming generation and SSEshared-types
@aryuki-dev/storage-sdkSubApp file sessions, R2 Binding and S3 adaptershared-types, billing-sdk
@aryuki-dev/transfer-clientBrowser transfer queue, multipart progress and resumeshared-types
@aryuki-dev/storage-vueVue upload queue and stylesVue 3.5 peer

Install

App revocation uses scope app. Use BillingBrowserClient for Checkout and Portal from the Billing browser origin. For server-side storage, use the attachment lifecycle methods.

Add the package scope to the project .npmrc and authenticate with a classic GitHub PAT that has read:packages and package access. Authorize the token for organization SSO where required.

@aryuki-dev:registry=https://npm.pkg.github.com

PowerShell:

npm.cmd login --scope=@aryuki-dev --auth-type=legacy --registry=https://npm.pkg.github.com
npm.cmd install --save-exact @aryuki-dev/shared-types@0.1.0-alpha.1 @aryuki-dev/auth-sdk@0.1.0-alpha.2 @aryuki-dev/billing-sdk@0.1.0-alpha.2

Git Bash:

npm login --scope=@aryuki-dev --auth-type=legacy --registry=https://npm.pkg.github.com
npm install --save-exact @aryuki-dev/shared-types@0.1.0-alpha.1 @aryuki-dev/auth-sdk@0.1.0-alpha.2 @aryuki-dev/billing-sdk@0.1.0-alpha.2

For Cloudflare Workers Builds, add the build secret GITHUB_PACKAGES_TOKEN with value <READ_PACKAGES_PAT> and commit the lockfile and the following variable reference in .npmrc.

@aryuki-dev:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}

Connect a SubApp

  1. Register the App ID, exact HTTPS callbacks and audience. Provision an independent service credential in the SubApp Worker.
  2. Use AuthClient.authorizeUrl(origin,{redirectUri,state,challenge}) with PKCE S256. Validate state before calling exchange({code,verifier,redirectUri},options). The BFF stores the returned SessionGrant server-side and sets a Secure, HttpOnly host-only cookie.
  3. Use refresh(refreshToken,requestId,options) with the same request ID for concurrent retries and revoke({scope},options) for logout. Read verifyUserToken(options,scope?) and getAppConfig(options) for scope and audience evidence. CLI Test Access uses exchangeTestAccess({name,secret,targetSubapp?},options) and legacy clients can call verifyLegacy(token,options).
  4. Pass a service credential and the matching user access token to Billing. usage(options) returns UsageSummary; entitlements(options) and listModels(options,capability?) return {items}. On the Billing browser origin, BillingBrowserClient.checkout({price_code,quantity,operation_id},signal?) returns an order ID and hosted URL. BillingBrowserClient.portal(signal?) returns a hosted URL. Availability depends on the environment. AiClient.generate({input,model_code?,operation_id},options) returns {request_id,text}; stream(input,options) yields typed SSE events.
  5. For files, call storagePolicy(appId,options), then reserveAttachment, commitAttachment, renewAttachment or releaseAttachment with the operation ID. The SubApp Worker uses createStorageHandler({appId,db,adapter,billing,authenticate}) and its own bucket. The browser can use TransferClient and optionally StorageUploader with UploadController and @aryuki-dev/storage-vue/style.css.
  6. As administrator, run a same-origin POST /admin/apps/{id}/integration-check, then use GET to read the last report. The Billing internal binding provides Registry and policy evidence at GET /v1/internal/apps/{id}/catalog-status. Review unknown or failed checks with the App owner. Reports are advisory and leave deployment and App state under owner control.

Use HttpTransport('https://accounts.aryuki.com') for an HTTP Auth client, or pass a Worker binding as ServiceBindingTransport(env.AUTH_SERVICE, 'https://accounts.aryuki.com'). Both accept RequestOptions with optional access and service tokens, idempotency and correlation IDs, and an abort signal. TypeScript signatures ship with each package. ApiError includes status, code, requestId, retryable and retryAfter. Common codes include invalid_client, invalid_grant, authentication_required, STORAGE_QUOTA_EXCEEDED, UPLOAD_SESSION_EXPIRED, IDEMPOTENCY_CONFLICT, BILLING_UNAVAILABLE and portal_unavailable. Reauthenticate on 401, check authorization on 403, reconcile a conflict on 409, and respect retry details on 429 and 503.

Run a local integration

Install shared-types, auth-sdk and billing-sdk from the commands above. Save the following as example.mjs and run node example.mjs. Both transports operate on synthetic data.

import assert from 'node:assert/strict';
import { HttpTransport, ServiceBindingTransport } from '@aryuki-dev/shared-types';
import { AuthClient } from '@aryuki-dev/auth-sdk';
import { BillingClient } from '@aryuki-dev/billing-sdk';

async function fetchFixture(request) {
  const { pathname } = new URL(request.url);
  if (pathname === '/v2/auth/token') return Response.json({
    access_token: 'fixture-access', refresh_token: 'fixture-refresh',
    token_type: 'Bearer', expires_in: 900,
  });
  if (pathname === '/v1/me/entitlements' && request.headers.get('authorization') === 'Bearer fixture-access') {
    return Response.json({ items: [{ app_id: 'demo', access: true }] });
  }
  return Response.json({ code: 'not_found' }, { status: 404 });
}
for (const transport of [
  new HttpTransport('https://fixture.example.invalid', fetchFixture),
  new ServiceBindingTransport({ fetch: fetchFixture }),
]) {
  const grant = await new AuthClient(transport, 'demo').exchange(
    { code: 'fixture-code', verifier: 'fixture-verifier', redirectUri: 'https://app.example.invalid/callback' },
    { serviceToken: 'fixture-service' },
  );
  const { items } = await new BillingClient(transport).entitlements({ accessToken: grant.access_token });
  assert.equal(items[0].access, true);
}
console.log('Both transports passed');

Updating and publishing

Pin a compatible package set and test persisted sessions, idempotent operations, HTTP and binding integration before upgrading. Use SemVer and keep existing published versions. Obtain authorization for each new release. Build, test, pack and inspect the archives, then publish shared-types first, followed by its consumers in dependency order. For this alpha series, use npm publish ./artifacts/<tarball>.tgz --registry=https://npm.pkg.github.com --access=restricted --tag=alpha. Verify each version with an independent install from GitHub Packages.

Billing links, callbacks and App versions

Use https://billing.aryuki.com/user for billing, subscription, usage and purchase links. Named workspace targets include ?view=usage, ?view=subscriptions, ?view=transactions, ?view=apps and ?view=storage. Billing resolves the workspace using its own administrator grants. Its public home and store are / and /store.

Register new Apps as V2. An App ID stays fixed, while its display name and exact HTTPS callback list can be edited. Legacy Apps retain their existing behavior until a confirmed conversion is acknowledged by Billing. Update and test the App's SDK integration first. If Billing reports a pending configuration, correct it and retry the same conversion. The integration check is diagnostic.

Enabled App capabilities determine whether AuthCenter shows Billing AI and storage analytics. Personal notifications share read status across both services. Billing retrieves profile and avatar information for the active AuthCenter identity.