@wervt/core 0.0.7 → 0.0.8

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { WervtAccess, WervtInvite, appAccess } from "./access.js";
2
+ import { WervtProfile, WervtProfileResult, appProfile } from "./profile.js";
2
3
  import { WervtError, errorResponse } from "./errors.js";
3
4
  import { WorkloadIdentity, workloadIdentity } from "./identity.js";
4
5
  import { IMAGE_FORMATS, ImageFormat, ImageGravity, ImageOptions, ImageSource, fetchImage, imageProcessingOptions, imageSourceKey, imageUrl, signImagePath } from "./image.js";
@@ -11,4 +12,4 @@ import { PUBLIC_FILE_SERVICE, publicFileResponse } from "./public-files.js";
11
12
  import { ShapeRequest, ShapeResponse, ShapeRowOf, parseTimestamp, proxyShape, shapeParser } from "./shape.js";
12
13
  import { ACCOUNT_MERGED_TASK, AccountMergedPayload, TASK_HEADER, Task, TaskEvent, TaskResult, createTaskHandler, defineTask, isTaskRequest, taskRunResponse } from "./tasks.js";
13
14
  import { AGENT_TOKEN_HEADER, AgentToken, USER_HEADER, USER_PROOF_HEADER, WervtRole, WervtUser, checkRole, getAgentToken, getUser, parseAgentToken, parseWervtUser, requireRole, userFromClaims } from "./user.js";
14
- export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, type AccountMergedPayload, type AgentToken, BUNDLE_MANIFEST, type BrandManifest, type BundleManifest, CACHE_CONTROL_PATTERN, IMAGE_FORMATS, type ImageFormat, type ImageGravity, type ImageOptions, type ImageSource, type MailMessage, PUBLIC_FILE_SERVICE, PUBLIC_PATH_PATTERN, type PreviewManifest, type PublicCacheRule, type PublicCacheRules, SERVICE_ERROR_HEADER, SERVICE_NAME_PATTERN, type ServiceManifest, type ServiceOptions, type ShapeRequest, type ShapeResponse, type ShapeRowOf, TASK_HEADER, type Task, type TaskEvent, type TaskResult, type TaskSchedule, type TasksManifest, USER_HEADER, USER_PROOF_HEADER, type WervtAccess, WervtError, type WervtInvite, type WervtRole, type WervtService, type WervtUser, type WorkloadIdentity, appAccess, appHeaders, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, matchesPublicPath, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, publicFileResponse, requireRole, runtimeUrl, sendMail, serviceManifests, serviceUrlVar, shapeParser, signImagePath, taskRunResponse, useService, userFromClaims, workloadIdentity };
15
+ export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, type AccountMergedPayload, type AgentToken, BUNDLE_MANIFEST, type BrandManifest, type BundleManifest, CACHE_CONTROL_PATTERN, IMAGE_FORMATS, type ImageFormat, type ImageGravity, type ImageOptions, type ImageSource, type MailMessage, PUBLIC_FILE_SERVICE, PUBLIC_PATH_PATTERN, type PreviewManifest, type PublicCacheRule, type PublicCacheRules, SERVICE_ERROR_HEADER, SERVICE_NAME_PATTERN, type ServiceManifest, type ServiceOptions, type ShapeRequest, type ShapeResponse, type ShapeRowOf, TASK_HEADER, type Task, type TaskEvent, type TaskResult, type TaskSchedule, type TasksManifest, USER_HEADER, USER_PROOF_HEADER, type WervtAccess, WervtError, type WervtInvite, type WervtProfile, type WervtProfileResult, type WervtRole, type WervtService, type WervtUser, type WorkloadIdentity, appAccess, appHeaders, appProfile, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, matchesPublicPath, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, publicFileResponse, requireRole, runtimeUrl, sendMail, serviceManifests, serviceUrlVar, shapeParser, signImagePath, taskRunResponse, useService, userFromClaims, workloadIdentity };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { WervtError, errorResponse } from "./errors.js";
2
2
  import { appHeaders, callRuntime, runtimeUrl } from "./runtime.js";
3
3
  import { AGENT_TOKEN_HEADER, USER_HEADER, USER_PROOF_HEADER, checkRole, getAgentToken, getUser, parseAgentToken, parseWervtUser, requireRole, userFromClaims } from "./user.js";
4
4
  import { appAccess } from "./access.js";
5
+ import { appProfile } from "./profile.js";
5
6
  import { workloadIdentity } from "./identity.js";
6
7
  import { IMAGE_FORMATS, fetchImage, imageProcessingOptions, imageSourceKey, imageUrl, signImagePath } from "./image.js";
7
8
  import { sendMail } from "./mail.js";
@@ -11,4 +12,4 @@ import { SERVICE_ERROR_HEADER, serviceUrlVar, useService } from "./service.js";
11
12
  import { PUBLIC_FILE_SERVICE, publicFileResponse } from "./public-files.js";
12
13
  import { parseTimestamp, proxyShape, shapeParser } from "./shape.js";
13
14
  import { ACCOUNT_MERGED_TASK, TASK_HEADER, createTaskHandler, defineTask, isTaskRequest, taskRunResponse } from "./tasks.js";
14
- export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, BUNDLE_MANIFEST, CACHE_CONTROL_PATTERN, IMAGE_FORMATS, PUBLIC_FILE_SERVICE, PUBLIC_PATH_PATTERN, SERVICE_ERROR_HEADER, SERVICE_NAME_PATTERN, TASK_HEADER, USER_HEADER, USER_PROOF_HEADER, WervtError, appAccess, appHeaders, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, matchesPublicPath, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, publicFileResponse, requireRole, runtimeUrl, sendMail, serviceManifests, serviceUrlVar, shapeParser, signImagePath, taskRunResponse, useService, userFromClaims, workloadIdentity };
15
+ export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, BUNDLE_MANIFEST, CACHE_CONTROL_PATTERN, IMAGE_FORMATS, PUBLIC_FILE_SERVICE, PUBLIC_PATH_PATTERN, SERVICE_ERROR_HEADER, SERVICE_NAME_PATTERN, TASK_HEADER, USER_HEADER, USER_PROOF_HEADER, WervtError, appAccess, appHeaders, appProfile, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, matchesPublicPath, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, publicFileResponse, requireRole, runtimeUrl, sendMail, serviceManifests, serviceUrlVar, shapeParser, signImagePath, taskRunResponse, useService, userFromClaims, workloadIdentity };
@@ -0,0 +1,25 @@
1
+ /** The signed-in user's name and picture after a change. */
2
+ export interface WervtProfileResult {
3
+ name: string;
4
+ /** The picture's URL, missing without one. */
5
+ image?: string;
6
+ }
7
+ export interface WervtProfile {
8
+ /** Sets the name (trimmed, at most 100 characters). */
9
+ setName(name: string): Promise<WervtProfileResult>;
10
+ /** Sets the picture: a JPEG, PNG or WebP image of at most 2 MB. Shrink it in the browser first. */
11
+ setImage(image: Uint8Array | ArrayBuffer | Blob): Promise<WervtProfileResult>;
12
+ /** Removes the picture. */
13
+ removeImage(): Promise<WervtProfileResult>;
14
+ }
15
+ /**
16
+ * Changes the name and picture of the user of `request`, without sending them to the account page.
17
+ * Only for apps an admin allowed it (dashboard, the app's settings). Never someone else's
18
+ * account, and never the address: link to `/_wervt/account` for that. The app sees the change
19
+ * from the next request on, in `useWervtUser` too.
20
+ *
21
+ * Throws a WervtError with the platform's status: 401 without a signed-in user, 403 when the app
22
+ * isn't allowed or is a preview, 400 for a name it can't take, 413 for a picture over 2 MB, 415
23
+ * for one that isn't JPEG, PNG or WebP, 503 in local dev.
24
+ */
25
+ export declare function appProfile(request: Request): WervtProfile;
@@ -0,0 +1,47 @@
1
+ import { callRuntime } from "./runtime.js";
2
+ import { USER_HEADER, USER_PROOF_HEADER } from "./user.js";
3
+ // src/profile.ts
4
+ /** Base64 in chunks: spreading a 2 MB array into one call overflows the stack. */
5
+ function toBase64(bytes) {
6
+ let binary = "";
7
+ for (let i = 0; i < bytes.length; i += 32768) binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
8
+ return btoa(binary);
9
+ }
10
+ async function bytesOf(image) {
11
+ if (image instanceof Uint8Array) return image;
12
+ if (image instanceof ArrayBuffer) return new Uint8Array(image);
13
+ return new Uint8Array(await image.arrayBuffer());
14
+ }
15
+ /**
16
+ * Changes the name and picture of the user of `request`, without sending them to the account page.
17
+ * Only for apps an admin allowed it (dashboard, the app's settings). Never someone else's
18
+ * account, and never the address: link to `/_wervt/account` for that. The app sees the change
19
+ * from the next request on, in `useWervtUser` too.
20
+ *
21
+ * Throws a WervtError with the platform's status: 401 without a signed-in user, 403 when the app
22
+ * isn't allowed or is a preview, 400 for a name it can't take, 413 for a picture over 2 MB, 415
23
+ * for one that isn't JPEG, PNG or WebP, 503 in local dev.
24
+ */
25
+ function appProfile(request) {
26
+ const headers = {
27
+ [USER_HEADER]: request.headers.get("x-wervt-user") ?? "",
28
+ [USER_PROOF_HEADER]: request.headers.get("x-wervt-user-proof") ?? ""
29
+ };
30
+ const change = async (body) => {
31
+ const result = await callRuntime("/_wervt/profile", {
32
+ method: "PATCH",
33
+ body,
34
+ headers
35
+ });
36
+ return {
37
+ name: result.name,
38
+ ...result.image ? { image: result.image } : {}
39
+ };
40
+ };
41
+ return {
42
+ setName: (name) => change({ name }),
43
+ setImage: async (image) => change({ image: toBase64(await bytesOf(image)) }),
44
+ removeImage: () => change({ image: null })
45
+ };
46
+ }
47
+ export { appProfile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wervt/core",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Server SDK for apps on wervt, on web standards: the signed-in user, live data, mail, tasks and workload identity, for any framework.",
5
5
  "keywords": [
6
6
  "electric",