@assinafy/cli 2.0.3 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,347 @@
1
+ # OAuth connections for marketplace apps
2
+
3
+ Assinafy uses OAuth 2.1 authorization code with mandatory S256 PKCE for public and confidential clients. The SDK implements the four published resource operations plus authorization-server discovery, authorization URL creation, and callback validation. The [official integration guide](https://api.assinafy.com.br/v1/docs) defines the protocol; [api-reference.md](./api-reference.md#oauth) contains the complete published HTTP request and response examples.
4
+
5
+ Use a separate connection for each customer workspace. An OAuth access token carries the consenting user's permissions, the granted scopes, and exactly one workspace. It never grants billing, workspace creation/deletion, API-key management, or other platform administration. An API key remains available for direct owner integrations. Signer access codes remain a separate authentication mechanism.
6
+
7
+ ## Register the application
8
+
9
+ In Assinafy settings, create an OAuth application with its display name, permitted scopes, and exact HTTPS redirect URIs. Redirects cannot contain fragments. Plain HTTP localhost callbacks are not supported; use an HTTPS development endpoint or tunnel. Public clients omit a secret. Confidential clients keep their secret on the server and use `client_secret_post`, never browser code, a distributed binary, or a repository.
10
+
11
+ Production endpoints:
12
+
13
+ | Purpose | URL |
14
+ | --- | --- |
15
+ | Protected-resource discovery | `https://api.assinafy.com.br/.well-known/oauth-protected-resource` |
16
+ | Issuer | `https://auth.assinafy.com.br` |
17
+ | Authorization-server discovery | `https://auth.assinafy.com.br/.well-known/oauth-authorization-server` |
18
+ | Authorization | `https://auth.assinafy.com.br/oauth/authorize` |
19
+ | Token | `https://api.assinafy.com.br/v1/oauth/token` |
20
+ | Revocation | `https://api.assinafy.com.br/v1/oauth/revoke` |
21
+ | UserInfo | `https://api.assinafy.com.br/v1/oauth/userinfo` |
22
+ | Resource indicator | `https://api.assinafy.com.br` |
23
+
24
+ The resource indicator is an origin, distinct from the SDK `baseUrl`, which includes `/v1`. Discover the issuer and endpoints for the environment you use. A sandbox API-key account does not imply that the same deployment supports OAuth or that production application credentials work there.
25
+
26
+ ## Choose scopes
27
+
28
+ | Scope | Purpose |
29
+ | --- | --- |
30
+ | `documents:read` | Read documents and signing state. |
31
+ | `documents:write` | Upload and manage documents and request signatures. |
32
+ | `templates:read` | Read templates. |
33
+ | `templates:write` | Permitted template operations. |
34
+ | `account:read` | Read the selected workspace. |
35
+ | `openid` | Request OpenID Connect identity and UserInfo. |
36
+ | `profile` | Include permitted profile claims. |
37
+ | `email` | Include permitted email claims. |
38
+ | `offline_access` | Request rotating refresh tokens for background work. |
39
+
40
+ `oauth connect` requests all nine published scopes by default so the CLI can access documents, templates, the selected workspace, and UserInfo, and obtain refresh tokens. The public application registration must permit all nine. Existing connections need a new authorization with the larger scope set; refreshing an old token does not add permissions. Use `--scope` to explicitly select fewer scopes when needed. For other applications, request only scopes they use. Resource metadata lists API scopes; authorization-server metadata also describes authentication features such as `offline_access`. The returned `scope` string is authoritative for the access token; do not infer granted scopes from what the browser requested. A scope never bypasses a user's role or the token's workspace boundary. Billing, subscriptions, workspace membership, credential management, and administration remain unavailable to OAuth tokens; those CLI operations require the non-OAuth credential documented for each endpoint.
41
+
42
+ ## Discover and start authorization
43
+
44
+ ```ts
45
+ import { AssinafyClient } from '@assinafy/cli/api';
46
+
47
+ const oauthClient = new AssinafyClient({ allowUnauthenticated: true });
48
+ const resource = await oauthClient.oauth.metadata();
49
+ const server = await oauthClient.oauth.discovery(resource.authorization_servers[0]!);
50
+ const request = await oauthClient.oauth.authorize({
51
+ clientId: process.env.ASSINAFY_OAUTH_CLIENT_ID!,
52
+ redirectUri: 'https://example.com/assinafy/callback',
53
+ scopes: ['documents:read', 'documents:write', 'account:read', 'offline_access'],
54
+ });
55
+ ```
56
+
57
+ `metadata()` has no input or body. Its direct JSON response is:
58
+
59
+ ```json
60
+ {
61
+ "resource": "https://api.assinafy.com.br",
62
+ "authorization_servers": ["https://auth.assinafy.com.br"],
63
+ "scopes_supported": ["documents:read", "documents:write", "templates:read", "templates:write", "account:read", "openid", "profile", "email"],
64
+ "bearer_methods_supported": ["header"]
65
+ }
66
+ ```
67
+
68
+ `discovery(issuer)` has no request body and returns `IOAuthAuthorizationServer`, including:
69
+
70
+ ```json
71
+ {
72
+ "issuer": "https://auth.assinafy.com.br",
73
+ "authorization_endpoint": "https://auth.assinafy.com.br/oauth/authorize",
74
+ "token_endpoint": "https://api.assinafy.com.br/v1/oauth/token",
75
+ "revocation_endpoint": "https://api.assinafy.com.br/v1/oauth/revoke",
76
+ "userinfo_endpoint": "https://api.assinafy.com.br/v1/oauth/userinfo",
77
+ "jwks_uri": "https://auth.assinafy.com.br/.well-known/jwks.json",
78
+ "scopes_supported": ["documents:read", "documents:write", "templates:read", "templates:write", "account:read", "openid", "profile", "email", "offline_access"],
79
+ "response_types_supported": ["code"],
80
+ "grant_types_supported": ["authorization_code", "refresh_token"],
81
+ "code_challenge_methods_supported": ["S256"],
82
+ "token_endpoint_auth_methods_supported": ["client_secret_post", "none"],
83
+ "authorization_response_iss_parameter_supported": true,
84
+ "client_id_metadata_document_supported": true
85
+ }
86
+ ```
87
+
88
+ `authorize(options)` performs both discovery requests and returns this complete `IOAuthAuthorizationRequest` shape. Values below are illustrations; each real invocation generates fresh cryptographic randomness. `nonce` is included only when `openid` is requested.
89
+
90
+ ```ts
91
+ interface IOAuthAuthorizationRequest {
92
+ authorization_url: string;
93
+ code_verifier: string;
94
+ state: string;
95
+ issuer: string;
96
+ client_id: string;
97
+ redirect_uri: string;
98
+ resource: string;
99
+ nonce?: string;
100
+ }
101
+ ```
102
+
103
+ The authorization URL contains `response_type=code`, `client_id`, `redirect_uri`, a space-separated `scope`, random `state`, `code_challenge=BASE64URL(SHA256(code_verifier))`, `code_challenge_method=S256`, `resource`, and optional `nonce`. The verifier is 43 base64url characters generated from 32 random bytes. Never put the verifier or client secret in the authorization URL.
104
+
105
+ Store the entire request server-side in the initiating user's authenticated session with a short expiry. Bind it to that user and consume it once. Redirect the browser to `request.authorization_url`; Assinafy handles login, workspace selection, and consent. The SDK creates protocol values, but does not implement your session store, browser routing, expiry, or single-use consumption.
106
+
107
+ ## Validate the callback and exchange the code
108
+
109
+ A successful callback includes `code`, `state`, and `iss`:
110
+
111
+ ```text
112
+ https://example.com/assinafy/callback?code=example_code&state=example_state&iss=https%3A%2F%2Fauth.assinafy.com.br
113
+ ```
114
+
115
+ Load and atomically consume the pending request for the same user. Pass the complete callback URL and stored request to the SDK:
116
+
117
+ ```ts
118
+ const tokens = await oauthClient.oauth.exchangeCode(
119
+ callbackUrl,
120
+ pendingRequest,
121
+ process.env.ASSINAFY_OAUTH_CLIENT_SECRET, // undefined for a public app
122
+ );
123
+ ```
124
+
125
+ `exchangeCode(callbackUrl, request, clientSecret?)` checks the callback origin/path and registered query parameters, rejects duplicate protocol parameters, compares `state` in constant time, and requires the exact stored issuer. It rejects denied authorization before calling the token endpoint. Authorization codes expire after 60 seconds and can be used once. Exchange immediately and never retry a code blindly after a timeout.
126
+
127
+ An authorization error raises `ValidationError` with a bounded OAuth error code in `errors.oauthError` and the message, without retaining the callback URL. Unrecognized formats become `unknown_error`. For `invalid_scope`, check that the application registration permits every requested scope, including `offline_access`; do not treat the browser return as successful authorization.
128
+
129
+ For applications that already perform callback validation, `token(payload)` accepts the same complete code grant directly:
130
+
131
+ ```json
132
+ {
133
+ "grant_type": "authorization_code",
134
+ "client_id": "example_client_id",
135
+ "client_secret": "example_client_secret",
136
+ "code": "example_authorization_code",
137
+ "redirect_uri": "https://example.com/assinafy/callback",
138
+ "code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk",
139
+ "resource": "https://api.assinafy.com.br"
140
+ }
141
+ ```
142
+
143
+ The SDK posts JSON. Omit `client_secret` for public clients. `resource` is optional in the token request; if provided, use the authorization resource. A direct `token()` call does not validate a browser callback, state, issuer, or session. The verifier must contain 43–128 RFC 7636 unreserved characters.
144
+
145
+ Both methods return the direct `IOAuthTokenResponse`, without an Assinafy `{ data }` envelope:
146
+
147
+ ```json
148
+ {
149
+ "access_token": "example_access_token",
150
+ "token_type": "Bearer",
151
+ "expires_in": 3600,
152
+ "scope": "documents:read documents:write account:read openid profile email",
153
+ "refresh_token": "example_refresh_token",
154
+ "id_token": "example_id_token"
155
+ }
156
+ ```
157
+
158
+ `refresh_token` is optional and depends on `offline_access`. `id_token` is optional and depends on `openid`. The SDK preserves optional null values from the server. Calculate expiration from the time the token response is received and the returned `expires_in`.
159
+
160
+ If you use an ID token to establish identity, validate it with an OIDC library using the discovered JWKS: signature, allowed algorithm, issuer, audience, expiry, and the stored nonce. The SDK returns the token; it does not verify JWT signatures or claims. Decoding a JWT is not identity verification.
161
+
162
+ ## Bind the token to its workspace
163
+
164
+ ```ts
165
+ const connected = new AssinafyClient({ token: tokens.access_token });
166
+ const { data: workspaces } = await connected.workspaces.list();
167
+ if (workspaces.length !== 1) throw new Error('Expected one authorized workspace');
168
+ const accountId = workspaces[0]!.id;
169
+
170
+ const workspaceClient = new AssinafyClient({
171
+ token: tokens.access_token,
172
+ accountId,
173
+ });
174
+ const documents = await workspaceClient.documents.list({ page: 1, per_page: 20 });
175
+ ```
176
+
177
+ Persist the workspace ID with the application's tenant/customer ID, issuer, resource, client ID, granted scopes, expiry, and encrypted tokens. Obtain the workspace ID from the authenticated `/accounts` response, not a callback query or an untrusted front end. OAuth `GET /accounts` exposes only the authorized workspace. All data access in a marketplace application must select the connection belonging to the current tenant.
178
+
179
+ ## Refresh without losing the connection
180
+
181
+ `token(payload)` accepts the refresh grant:
182
+
183
+ ```ts
184
+ const next = await oauthClient.oauth.token({
185
+ grant_type: 'refresh_token',
186
+ client_id: process.env.ASSINAFY_OAUTH_CLIENT_ID!,
187
+ client_secret: process.env.ASSINAFY_OAUTH_CLIENT_SECRET,
188
+ refresh_token: storedRefreshToken,
189
+ resource: 'https://api.assinafy.com.br',
190
+ });
191
+ ```
192
+
193
+ The complete wire body is:
194
+
195
+ ```json
196
+ {
197
+ "grant_type": "refresh_token",
198
+ "client_id": "example_client_id",
199
+ "client_secret": "example_client_secret",
200
+ "refresh_token": "example_current_refresh_token",
201
+ "resource": "https://api.assinafy.com.br"
202
+ }
203
+ ```
204
+
205
+ Its response has the same token shape above, with new access and refresh values. Each successful refresh consumes the previous refresh token. Reusing it revokes the entire connection. Serialize refreshes per connection across every worker and process; atomically store the complete new response before releasing the lock or using it. A lock local to one process is insufficient for a distributed application.
206
+
207
+ The documented authorization lifetime is 30 days and is not extended by refresh. A transport timeout can leave rotation outcome unknown; do not replay the old token automatically. Mark that connection for recovery/reconnection. On `invalid_grant`, require new consent. The SDK has no automatic refresh or request retry and never persists tokens. Construct a new authenticated `AssinafyClient` with the current access token after rotation.
208
+
209
+ ## UserInfo and disconnect
210
+
211
+ `userinfo()` uses the current bearer token and requires `openid`; `profile` and `email` control optional claims. It has no request body and returns flat `IOAuthUserInfo`:
212
+
213
+ ```ts
214
+ const identity = await new AssinafyClient({ token: tokens.access_token }).oauth.userinfo();
215
+ ```
216
+
217
+ ```json
218
+ {
219
+ "sub": "example_user_id",
220
+ "name": "Example User",
221
+ "email": "user@example.com",
222
+ "email_verified": true
223
+ }
224
+ ```
225
+
226
+ Only `sub` is mandatory; other claims can be missing or null. Prefer the stable subject over an email address as an identity key, and include the issuer in that key.
227
+
228
+ To disconnect, `revoke(payload)` posts:
229
+
230
+ ```json
231
+ {
232
+ "token": "example_refresh_token",
233
+ "client_id": "example_client_id",
234
+ "client_secret": "example_client_secret",
235
+ "token_type_hint": "refresh_token"
236
+ }
237
+ ```
238
+
239
+ ```ts
240
+ await oauthClient.oauth.revoke({
241
+ token: storedRefreshToken,
242
+ client_id: process.env.ASSINAFY_OAUTH_CLIENT_ID!,
243
+ client_secret: process.env.ASSINAFY_OAUTH_CLIENT_SECRET,
244
+ token_type_hint: 'refresh_token',
245
+ });
246
+ ```
247
+
248
+ `token_type_hint` is optional and accepts `access_token` or `refresh_token`. Successful revocation returns HTTP 200 with no required response body; the SDK resolves to `undefined`. Unknown/already revoked tokens also succeed for an authenticated client. Invalid client authentication returns 401. Revoke the connection before removing local credentials when possible, then mark it disconnected and stop its background work. CLI success prints `{ "revoked": true }`, a local confirmation rather than an API response payload.
249
+
250
+ ## CLI flow
251
+
252
+ ### Automatic browser return
253
+
254
+ The distributed CLI includes the official **Public** application's client ID, `96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88`. This public identifier is not a secret. The CLI uses PKCE S256 and the scopes `account:read documents:read documents:write templates:read templates:write openid profile email offline_access`; keep the registered permissions consistent with the requested scopes. No client secret is used by `oauth connect`, including when `ASSINAFY_OAUTH_CLIENT_SECRET` is set for another application.
255
+
256
+ Application maintainers must deploy the callback from `integrations-generic-callback` and register this exact HTTPS URI, without an extension or trailing slash:
257
+
258
+ ```text
259
+ https://integrations.assinafy.com.br/assinafy-cli/oauth-callback
260
+ ```
261
+
262
+ Leave `ASSINAFY_OAUTH_CLIENT_ID` unset to use the official application. `connect`, `authorize`, `refresh`, and `revoke` resolve the client ID in this order: `--client-id`, `ASSINAFY_OAUTH_CLIENT_ID`, then the bundled ID. Use an override for your own application or another environment, with that application's registered callback and permissions. SDK calls still require an explicit client ID. Use a private directory outside the repository. On POSIX shells:
263
+
264
+ ```bash
265
+ umask 077
266
+ assinafy oauth connect --json > tokens.json
267
+ unset ASSINAFY_API_KEY
268
+ export ASSINAFY_TOKEN="$(jq -er '.access_token' tokens.json)"
269
+ assinafy workspaces list --json
270
+ # Select the single returned workspace as ASSINAFY_ACCOUNT_ID.
271
+ assinafy documents list --json
272
+ ```
273
+
274
+ `oauth connect` opens the system browser, waits for approval, and prints the complete flat token response described in the token-exchange section above. The authorization URL and browser instructions go to stderr, including with `--json` or `--quiet`; token output goes to stdout. It does not save a profile, persist tokens, or automatically refresh them. On Windows, restrict the output directory ACL before writing credentials.
275
+
276
+ | Option | Behavior |
277
+ | --- | --- |
278
+ | `--client-id <id>` | Override the bundled public application ID; takes precedence over `ASSINAFY_OAUTH_CLIENT_ID`. |
279
+ | `--redirect-uri <uri>` | Registered HTTPS relay URI; defaults to the extensionless URL above. Query parameters and fragments are unsupported for this browser relay. |
280
+ | `--scope '<scopes>'` | Space-separated scopes; defaults to `account:read documents:read documents:write templates:read templates:write openid profile email offline_access`. |
281
+ | `--timeout <seconds>` | Browser response deadline, 1–600 seconds; default 180. API calls use the SDK's network timeout. |
282
+ | `--no-browser` | Print the authorization URL for manual opening; the local listener still receives the return automatically. |
283
+
284
+ The browser must run on the same computer as the CLI. A browser on your laptop cannot reach a listener in a remote SSH session or container without deliberate port forwarding; use the manual flow below when appropriate. Ctrl+C cancels and closes the listener. If browser launch is unavailable, open the printed URL on the same computer. An expired authorization code requires a fresh connection attempt; it is never retried automatically.
285
+
286
+ The callback protocol is:
287
+
288
+ 1. Discover the API resource and issuer, generate a random 32-byte PKCE verifier and state, and bind an ephemeral port on `127.0.0.1` only.
289
+ 2. Set `state` to `<43-character base64url random value>.<local port>` and send the registered HTTPS `redirect_uri` with the S256 challenge. Keep the verifier in the CLI process.
290
+ 3. After consent, Assinafy returns `code`, `state`, and `iss` (or `error`) to the HTTPS page. The code is single-use and expires 60 seconds after approval.
291
+ 4. The standalone page clears its query from browser history, checks the exact state syntax (including rejection of trailing line breaks), port range, issuer allowlist, parameter uniqueness, and exactly one nonblank code or error, then navigates to `http://127.0.0.1:<port>/callback` with only `code`, `state`, `iss`, or `error`.
292
+ 5. The CLI accepts only GET on `/callback` with the exact loopback Host, the original state, and the discovered issuer. Malformed or unrelated requests do not consume the pending connection. A valid authorization response is accepted once; the browser receives a page clearing its query and directing the user to the terminal.
293
+ 6. Close the listener and remove its timeout/signal handlers. Reconstruct the response against the saved HTTPS redirect URI and call `oauth.exchangeCode`; the token request still uses that exact HTTPS URI. Tokens and the PKCE verifier are never sent to the callback site.
294
+
295
+ The local return page uses the logo, colors, Mona Sans fonts, and responsive layout hosted at `https://integrations.assinafy.com.br`. It distinguishes a received response, authorization failure, and invalid return. A received response does not confirm token exchange; check the CLI exit status and output. Browser history is cleared before loading assets, every response sends `Referrer-Policy: no-referrer`, and CSP permits only the fixed history script plus that origin's styles, images, and fonts. No callback parameters are included in the HTML or asset URLs. Public font responses must allow cross-origin loading from the temporary loopback origin.
296
+
297
+ The shared callback page accepts the production and staging issuers configured by the integration site. A custom issuer needs a compatible relay allowlist as well as `--base-url` and `--redirect-uri`. Do not add access logging, analytics, third-party scripts, or caching to callback routes. Deploy the site and register the application before using the default URL; installing the CLI does not deploy that site.
298
+
299
+ ### Manual authorization and exchange
300
+
301
+ For a server application or an existing callback handler, provision `ASSINAFY_OAUTH_CLIENT_ID` and, for a confidential app, `ASSINAFY_OAUTH_CLIENT_SECRET` through your secret manager. Use a private directory outside the repository:
302
+
303
+ ```bash
304
+ umask 077
305
+ assinafy oauth metadata --json
306
+ assinafy oauth discovery https://auth.assinafy.com.br --json
307
+ assinafy oauth authorize \
308
+ --redirect-uri https://example.com/assinafy/callback \
309
+ --scope 'documents:read documents:write account:read offline_access' \
310
+ --json > pending-request.json
311
+ jq -r '.authorization_url' pending-request.json
312
+ ```
313
+
314
+ Open the displayed URL and complete consent. Your HTTPS callback handler must capture the complete callback URL and supply it through `ASSINAFY_OAUTH_CALLBACK_URL` in the same private session. Then:
315
+
316
+ ```bash
317
+ assinafy oauth exchange --request pending-request.json --json > tokens.json
318
+ unset ASSINAFY_API_KEY
319
+ export ASSINAFY_TOKEN="$(jq -er '.access_token' tokens.json)"
320
+ assinafy workspaces list --json
321
+ ```
322
+
323
+ Select the single returned workspace as `ASSINAFY_ACCOUNT_ID`. Remove the consumed pending request. `authorize` does not launch a browser or start a listener; its state format is intended for your own callback, not the integration site's loopback relay.
324
+
325
+ ### Token use and rotation
326
+
327
+ An API key wins when both credential types are supplied at the same precedence level. A higher-precedence `--token` overrides environment or profile credentials as a group. Avoid leaving a stale `ASSINAFY_API_KEY` in an OAuth session.
328
+
329
+ Provision the current refresh token as `ASSINAFY_OAUTH_REFRESH_TOKEN`; `assinafy oauth refresh --resource https://api.assinafy.com.br --json` emits the rotated token response. Save to a private new file and atomically replace the previous file only on success. Never launch concurrent refresh commands. Use `ASSINAFY_OAUTH_REVOKE_TOKEN` for `assinafy oauth revoke --token-type-hint refresh_token --json`. For UserInfo, request `openid` during consent and run `assinafy oauth userinfo --json` with the access token.
330
+
331
+ Request files, callback URLs, token output, and environment variables are sensitive. Protect them using the OS's user-only permissions, keep them out of logs and version control, and remove consumed requests. The CLI's temporary listener serves only a browser handoff; token storage and connection lifecycle remain the caller's responsibility.
332
+
333
+ ## Failures and application lifecycle
334
+
335
+ | Result | Application behavior |
336
+ | --- | --- |
337
+ | `400 invalid_grant` | Code expired/used or refresh no longer usable; reconnect rather than retrying the old grant. |
338
+ | `401 invalid_client` | Check application type, client ID, client secret, and environment. |
339
+ | API `401` | Access token invalid/expired; perform one serialized refresh if the connection is recoverable. |
340
+ | `403` with `insufficient_scope` | Read `ApiError.wwwAuthenticate`; obtain consent for the missing scope. |
341
+ | Other `403` | Check user role, selected workspace, or a platform-administration restriction. |
342
+ | `429` | Respect `ApiError.retryAfter`; retry only operations whose semantics allow it. |
343
+ | Network failure on token exchange/refresh | Outcome may be ambiguous; never blindly replay a one-time credential. |
344
+
345
+ `ApiError.responseData` preserves `{ error, error_description? }` for OAuth failures. `wwwAuthenticate` preserves the Bearer challenge, including `scope` and `resource_metadata` when supplied. JSON CLI errors expose these as `error.details`, `error.wwwAuthenticate`, and `error.retryAfter`. Axios configuration and request credentials are not attached to SDK errors.
346
+
347
+ Unverified apps are limited to 25 workspaces by the documented platform policy. Complete application verification before wider marketplace distribution. Provide connection status, a user-triggered reconnect/disconnect flow, and tenant-scoped background jobs. Keep secrets on the server, use least-privilege scopes, and require the customer to consent to each connection.
package/docs/oauth.md ADDED
@@ -0,0 +1,162 @@
1
+ # `assinafy oauth`
2
+
3
+ ## `assinafy oauth`
4
+
5
+ ```text
6
+ Usage: assinafy oauth [options] [command]
7
+
8
+ OAuth 2.1 authorization, PKCE, token rotation, and OpenID Connect
9
+
10
+ Options:
11
+ -h, --help display help for command
12
+
13
+ Commands:
14
+ connect [options] Open browser consent for a public OAuth app, receive its
15
+ loopback return, and print tokens
16
+ metadata Read protected-resource metadata from the API origin
17
+ discovery <issuer> Read authorization-server metadata from an HTTPS issuer
18
+ authorize [options] Create an authorization URL and a sensitive PKCE/state
19
+ request; save the JSON securely
20
+ exchange [options] Validate the callback against a saved authorization
21
+ request and exchange its code
22
+ refresh [options] Rotate a refresh token once; securely persist the full
23
+ response before using it
24
+ revoke [options] Revoke an access or refresh token for this application
25
+ userinfo Read OIDC claims using --token / ASSINAFY_TOKEN with
26
+ openid scope
27
+ help [command] display help for command
28
+ ```
29
+
30
+ ### `assinafy oauth connect`
31
+
32
+ ```text
33
+ Usage: assinafy oauth connect [options]
34
+
35
+ Open browser consent for a public OAuth app, receive its loopback return, and
36
+ print tokens
37
+
38
+ Options:
39
+ --client-id <id> OAuth application client ID (default:
40
+ "96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88", env:
41
+ ASSINAFY_OAUTH_CLIENT_ID)
42
+ --redirect-uri <uri> Exactly registered HTTPS relay URI (default:
43
+ "https://integrations.assinafy.com.br/assinafy-cli/oauth-callback")
44
+ --scope <scopes> Space-separated scopes; defaults to all supported OAuth
45
+ scopes (default: "account:read documents:read
46
+ documents:write templates:read templates:write openid
47
+ profile email offline_access")
48
+ --timeout <seconds> Wait for browser consent (1–600 seconds) (default:
49
+ "180")
50
+ --no-browser Print the authorization URL without opening the system
51
+ browser
52
+ -h, --help display help for command
53
+ ```
54
+
55
+ ### `assinafy oauth metadata`
56
+
57
+ ```text
58
+ Usage: assinafy oauth metadata [options]
59
+
60
+ Read protected-resource metadata from the API origin
61
+
62
+ Options:
63
+ -h, --help display help for command
64
+ ```
65
+
66
+ ### `assinafy oauth discovery`
67
+
68
+ ```text
69
+ Usage: assinafy oauth discovery [options] <issuer>
70
+
71
+ Read authorization-server metadata from an HTTPS issuer
72
+
73
+ Arguments:
74
+ issuer Issuer from protected-resource metadata
75
+
76
+ Options:
77
+ -h, --help display help for command
78
+ ```
79
+
80
+ ### `assinafy oauth authorize`
81
+
82
+ ```text
83
+ Usage: assinafy oauth authorize [options]
84
+
85
+ Create an authorization URL and a sensitive PKCE/state request; save the JSON
86
+ securely
87
+
88
+ Options:
89
+ --client-id <id> OAuth application client ID (default:
90
+ "96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88", env:
91
+ ASSINAFY_OAUTH_CLIENT_ID)
92
+ --redirect-uri <uri> Exactly registered HTTPS callback URI
93
+ --scope <scopes> Space-separated scopes; offline_access requests refresh
94
+ tokens
95
+ -h, --help display help for command
96
+ ```
97
+
98
+ ### `assinafy oauth exchange`
99
+
100
+ ```text
101
+ Usage: assinafy oauth exchange [options]
102
+
103
+ Validate the callback against a saved authorization request and exchange its
104
+ code
105
+
106
+ Options:
107
+ --request <path> Private JSON file returned by oauth authorize
108
+ --callback-url <url> Complete callback URL with code, state, and iss
109
+ (env: ASSINAFY_OAUTH_CALLBACK_URL)
110
+ --client-secret <secret> Confidential application secret; omit for public
111
+ applications (env: ASSINAFY_OAUTH_CLIENT_SECRET)
112
+ -h, --help display help for command
113
+ ```
114
+
115
+ ### `assinafy oauth refresh`
116
+
117
+ ```text
118
+ Usage: assinafy oauth refresh [options]
119
+
120
+ Rotate a refresh token once; securely persist the full response before using it
121
+
122
+ Options:
123
+ --client-id <id> OAuth application client ID (default:
124
+ "96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88",
125
+ env: ASSINAFY_OAUTH_CLIENT_ID)
126
+ --client-secret <secret> Confidential application secret; omit for public
127
+ applications (env: ASSINAFY_OAUTH_CLIENT_SECRET)
128
+ --refresh-token <token> Current refresh token (env:
129
+ ASSINAFY_OAUTH_REFRESH_TOKEN)
130
+ --resource <uri> Resource indicator used during authorization
131
+ -h, --help display help for command
132
+ ```
133
+
134
+ ### `assinafy oauth revoke`
135
+
136
+ ```text
137
+ Usage: assinafy oauth revoke [options]
138
+
139
+ Revoke an access or refresh token for this application
140
+
141
+ Options:
142
+ --client-id <id> OAuth application client ID (default:
143
+ "96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88",
144
+ env: ASSINAFY_OAUTH_CLIENT_ID)
145
+ --client-secret <secret> Confidential application secret; omit for public
146
+ applications (env: ASSINAFY_OAUTH_CLIENT_SECRET)
147
+ --revoke-token <token> Token to revoke (env: ASSINAFY_OAUTH_REVOKE_TOKEN)
148
+ --token-type-hint <type> Type of token being revoked (choices:
149
+ "access_token", "refresh_token")
150
+ -h, --help display help for command
151
+ ```
152
+
153
+ ### `assinafy oauth userinfo`
154
+
155
+ ```text
156
+ Usage: assinafy oauth userinfo [options]
157
+
158
+ Read OIDC claims using --token / ASSINAFY_TOKEN with openid scope
159
+
160
+ Options:
161
+ -h, --help display help for command
162
+ ```
package/docs/releasing.md CHANGED
@@ -1,15 +1,12 @@
1
1
  # Release runbook
2
2
 
3
- Releases originate from the source GitLab repository. Its push mirror must send
4
- branches and `v*` tags to GitHub; GitHub Release objects are created by
5
- `.github/workflows/release.yml`, not by the mirror.
3
+ This repository is hosted directly on GitHub. Push `main` and the matching
4
+ annotated `v*` tag to `assinafy/assinafy-cli`. GitHub Release objects are created
5
+ by `.github/workflows/release.yml` after the verification job succeeds.
6
6
 
7
7
  ## One-time repository setup
8
8
 
9
9
  - Create a protected GitHub environment named `release` for the publish job.
10
- - Create a protected `sandbox` environment for `.github/workflows/sandbox.yml` and
11
- configure its four `ASSINAFY_SANDBOX_*` secrets described in `CONTRIBUTING.md`.
12
- Do not require a reviewer if the scheduled weekly run must execute unattended.
13
10
  - Configure npm trusted publishing for this GitHub repository, workflow
14
11
  `release.yml`, and environment `release`. No long-lived npm token is used.
15
12
  - Allow the repository `GITHUB_TOKEN` to write GitHub Releases and Packages.
@@ -28,10 +25,18 @@ branches and `v*` tags to GitHub; GitHub Release objects are created by
28
25
  the release commit. Commit the generated API reference when the official
29
26
  contract changes.
30
27
  2. Set `package.json` to the exact SemVer version and push the matching signed or
31
- annotated `vX.Y.Z` tag from GitLab.
28
+ annotated `vX.Y.Z` tag to GitHub.
32
29
  3. Confirm the GitHub workflow verifies that exact tag/commit, uploads its checked
33
30
  artifact, publishes both registries, and only then publishes the draft release.
34
31
 
32
+ The `publish` job depends on `verify`, which runs the automated SDK and CLI tests,
33
+ type and lint checks, current public production API contract check, generated-file
34
+ checks, packaged consumer checks, installer checks, and reproducible archive and
35
+ checksum validation. It then uploads one verified payload for publication. Tests
36
+ use controlled transports and local servers; verification requires no Assinafy
37
+ account credentials. Publishing retains its protected `release` environment and
38
+ registry authentication.
39
+
35
40
  Prerelease versions advance the `next` registry tag and are not marked as the
36
41
  latest GitHub release. Stable versions advance `latest`. The workflow compares
37
42
  SemVer precedence before moving either registry/GitHub pointer; an older backfill