@x12i/keyrox-store-pg 0.0.0-stage → 0.1.1

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.
Files changed (88) hide show
  1. package/dist/database.d.ts +10 -0
  2. package/dist/database.d.ts.map +1 -0
  3. package/dist/database.js +28 -0
  4. package/dist/database.js.map +1 -0
  5. package/dist/directory-access-sql.d.ts +12 -0
  6. package/dist/directory-access-sql.d.ts.map +1 -0
  7. package/dist/directory-access-sql.js +253 -0
  8. package/dist/directory-access-sql.js.map +1 -0
  9. package/dist/directory-sql.d.ts +8 -0
  10. package/dist/directory-sql.d.ts.map +1 -0
  11. package/dist/directory-sql.js +1052 -0
  12. package/dist/directory-sql.js.map +1 -0
  13. package/dist/hosted-human-sessions.d.ts +5 -0
  14. package/dist/hosted-human-sessions.d.ts.map +1 -0
  15. package/dist/hosted-human-sessions.js +105 -0
  16. package/dist/hosted-human-sessions.js.map +1 -0
  17. package/dist/index.d.ts +21 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +59 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/migrate.d.ts +4 -0
  22. package/dist/migrate.d.ts.map +1 -0
  23. package/dist/migrate.js +51 -0
  24. package/dist/migrate.js.map +1 -0
  25. package/dist/notification-deliveries.d.ts +5 -0
  26. package/dist/notification-deliveries.d.ts.map +1 -0
  27. package/dist/notification-deliveries.js +81 -0
  28. package/dist/notification-deliveries.js.map +1 -0
  29. package/dist/notification-webhook-sql.d.ts +4 -0
  30. package/dist/notification-webhook-sql.d.ts.map +1 -0
  31. package/dist/notification-webhook-sql.js +109 -0
  32. package/dist/notification-webhook-sql.js.map +1 -0
  33. package/dist/rows.d.ts +54 -0
  34. package/dist/rows.d.ts.map +1 -0
  35. package/dist/rows.js +426 -0
  36. package/dist/rows.js.map +1 -0
  37. package/dist/sql-store.d.ts +4 -0
  38. package/dist/sql-store.d.ts.map +1 -0
  39. package/dist/sql-store.js +1350 -0
  40. package/dist/sql-store.js.map +1 -0
  41. package/migrations/001_init.sql +260 -0
  42. package/migrations/002_apps.sql +36 -0
  43. package/migrations/003_environments.sql +46 -0
  44. package/migrations/004_sso.sql +62 -0
  45. package/migrations/005_workloads.sql +64 -0
  46. package/migrations/006_directory.sql +155 -0
  47. package/migrations/007_account_sso.sql +40 -0
  48. package/migrations/008_app_sign_in.sql +26 -0
  49. package/migrations/009_account_sso_next.sql +4 -0
  50. package/migrations/010_account_sso_profile.sql +14 -0
  51. package/migrations/011_hosted_sso_profiles.sql +26 -0
  52. package/migrations/012_app_signup_roles.sql +2 -0
  53. package/migrations/013_product_role_catalog.sql +14 -0
  54. package/migrations/014_application_staff_access.sql +21 -0
  55. package/migrations/015_audit_service_actor.sql +7 -0
  56. package/migrations/016_app_waitlist_questions.sql +2 -0
  57. package/migrations/017_app_signup_policy.sql +9 -0
  58. package/migrations/018_managed_app_sign_in.sql +8 -0
  59. package/migrations/019_hosted_sso_email_proofs.sql +12 -0
  60. package/migrations/020_cli_login_codes.sql +15 -0
  61. package/migrations/021_hosted_email_codes.sql +18 -0
  62. package/migrations/022_sso_waitlist_callback.sql +3 -0
  63. package/migrations/023_app_email_code_sign_in.sql +1 -0
  64. package/migrations/024_hosted_auth_copy.sql +2 -0
  65. package/migrations/025_app_directory_workspaces.sql +55 -0
  66. package/migrations/027_role_features_and_configuration.sql +17 -0
  67. package/migrations/028_sso_only_signup_audience.sql +4 -0
  68. package/migrations/029_people_only_directory_model.sql +3 -0
  69. package/migrations/030_typed_questionnaires.sql +3 -0
  70. package/migrations/031_app_notifications.sql +22 -0
  71. package/migrations/032_agent_grant_duration.sql +10 -0
  72. package/migrations/033_application_lifecycle.sql +67 -0
  73. package/migrations/034_notification_deliveries.sql +25 -0
  74. package/migrations/035_app_notification_webhook_jobs.sql +28 -0
  75. package/migrations/036_account_notification_recovery.sql +11 -0
  76. package/migrations/037_waitlist_confirmation.sql +7 -0
  77. package/migrations/039_hosted_human_sessions.sql +45 -0
  78. package/migrations/040_hosted_human_clients.sql +35 -0
  79. package/migrations/041_app_workspace_invitations.sql +9 -0
  80. package/migrations/042_directory_email_proof.sql +16 -0
  81. package/migrations/043_sso_exchange_redirect_uri.sql +1 -0
  82. package/migrations/044_repair_app_sign_in_connections.sql +30 -0
  83. package/migrations/045_directory_integrity.sql +140 -0
  84. package/migrations/046_person_email_across_organizations.sql +7 -0
  85. package/migrations/047_owner_access.sql +35 -0
  86. package/migrations/048_invitation_links.sql +28 -0
  87. package/package.json +36 -4
  88. package/README.md +0 -3
@@ -0,0 +1,109 @@
1
+ import { time } from "./rows.js";
2
+ const destination = `
3
+ FROM app_environments env
4
+ JOIN applications app ON app.id = env.app_id AND app.org_id = env.org_id
5
+ JOIN app_notification_settings settings ON settings.environment_id = env.id AND settings.org_id = env.org_id
6
+ JOIN app_notification_webhooks hook ON hook.environment_id = env.id AND hook.org_id = env.org_id
7
+ WHERE app.trashed_at IS NULL AND app.status = 'active' AND env.status = 'active' AND hook.enabled
8
+ `;
9
+ const canRetry = `job.status = 'failed' AND job.expires_at > $4::timestamptz AND job.body_enc IS NOT NULL AND job.attempt_count < 10
10
+ AND EXISTS (SELECT 1 ${destination}
11
+ AND app.id = job.app_id AND env.id = job.environment_id AND env.org_id = job.organization_id
12
+ AND env.key_version = job.environment_key_version AND hook.id = job.webhook_id
13
+ AND settings.delivery = CASE WHEN job.keyrox_delivery THEN 'both' ELSE 'webhook' END)`;
14
+ function optionalTime(row, key) {
15
+ return row[key] == null ? null : time(row, key);
16
+ }
17
+ function summary(row) {
18
+ return {
19
+ id: String(row.id), eventId: String(row.event_id), webhookId: String(row.webhook_id), type: String(row.type),
20
+ status: row.status, attemptCount: Number(row.attempt_count),
21
+ lastHttpStatus: row.last_http_status == null ? null : Number(row.last_http_status),
22
+ failureCode: row.failure_code == null ? null : String(row.failure_code),
23
+ createdAt: time(row, "created_at"), updatedAt: time(row, "updated_at"), expiresAt: time(row, "expires_at"),
24
+ nextAttemptAt: optionalTime(row, "next_attempt_at"), retryable: row.retryable === true,
25
+ };
26
+ }
27
+ function jobOf(row) {
28
+ const { retryable: _retryable, ...metadata } = summary(row);
29
+ return {
30
+ ...metadata,
31
+ organizationId: String(row.organization_id), environmentId: String(row.environment_id), appId: String(row.app_id),
32
+ environmentKeyVersion: Number(row.environment_key_version), keyroxDelivery: row.keyrox_delivery === true,
33
+ bodyEnc: row.body_enc == null ? null : String(row.body_enc),
34
+ leaseToken: row.lease_token == null ? null : String(row.lease_token), leasedUntil: optionalTime(row, "leased_until"),
35
+ };
36
+ }
37
+ export function createSqlNotificationWebhookJobs(tx) {
38
+ return {
39
+ enqueueNotificationWebhooks(jobs) {
40
+ return tx(async (sql) => {
41
+ let available = false;
42
+ for (const job of jobs) {
43
+ const current = await sql.query(`SELECT hook.id ${destination}
44
+ AND app.id = $1 AND env.id = $2 AND env.org_id = $3 AND env.key_version = $4 AND hook.id = $5 AND settings.delivery = $6
45
+ FOR SHARE OF app, env, settings, hook`, [job.appId, job.environmentId, job.organizationId, job.environmentKeyVersion, job.webhookId, job.keyroxDelivery ? "both" : "webhook"]);
46
+ if (!current.rows.length)
47
+ continue;
48
+ await sql.query(`INSERT INTO app_notification_webhook_jobs (
49
+ id, event_id, webhook_id, organization_id, app_id, environment_id, environment_key_version, type,
50
+ body_enc, keyrox_delivery, status, created_at, updated_at, expires_at, next_attempt_at
51
+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, 'queued', $11::timestamptz, $11::timestamptz, $12::timestamptz, $11::timestamptz)
52
+ ON CONFLICT (id) DO NOTHING`, [job.id, job.eventId, job.webhookId, job.organizationId, job.appId, job.environmentId, job.environmentKeyVersion,
53
+ job.type, job.bodyEnc, job.keyroxDelivery, job.createdAt, job.expiresAt]);
54
+ available = true;
55
+ }
56
+ return available;
57
+ });
58
+ },
59
+ claimNotificationWebhooks({ now, leaseToken, leasedUntil, eventId, limit }) {
60
+ return tx(async (sql) => {
61
+ const result = await sql.query(`WITH due AS (
62
+ SELECT id FROM app_notification_webhook_jobs
63
+ WHERE status = 'queued' AND body_enc IS NOT NULL AND expires_at > $1::timestamptz AND next_attempt_at <= $1::timestamptz
64
+ AND (leased_until IS NULL OR leased_until <= $1::timestamptz) AND ($4::text IS NULL OR event_id = $4)
65
+ ORDER BY next_attempt_at, id LIMIT $5 FOR UPDATE SKIP LOCKED
66
+ )
67
+ UPDATE app_notification_webhook_jobs job SET lease_token = $2, leased_until = $3::timestamptz, attempt_count = job.attempt_count + 1
68
+ FROM due WHERE job.id = due.id RETURNING job.*`, [now, leaseToken, leasedUntil, eventId ?? null, limit]);
69
+ return result.rows.map(jobOf);
70
+ });
71
+ },
72
+ completeNotificationWebhook(id, leaseToken, result) {
73
+ return tx(async (sql) => {
74
+ await sql.query(`UPDATE app_notification_webhook_jobs SET
75
+ body_enc = $3, status = $4, last_http_status = $5, failure_code = $6, updated_at = $7::timestamptz,
76
+ next_attempt_at = $8::timestamptz, lease_token = NULL, leased_until = NULL
77
+ WHERE id = $1 AND lease_token = $2`, [id, leaseToken, result.bodyEnc, result.status, result.lastHttpStatus, result.failureCode, result.updatedAt, result.nextAttemptAt]);
78
+ });
79
+ },
80
+ listNotificationWebhookJobs(environmentId, organizationId, limit, now) {
81
+ return tx(async (sql) => {
82
+ const result = await sql.query(`SELECT
83
+ id, event_id, webhook_id, type, status, attempt_count, last_http_status, failure_code, created_at, updated_at, expires_at, next_attempt_at,
84
+ (${canRetry}) AS retryable
85
+ FROM app_notification_webhook_jobs job WHERE environment_id = $1 AND organization_id = $2 ORDER BY created_at DESC, id DESC LIMIT $3`, [environmentId, organizationId, limit, now]);
86
+ return result.rows.map(summary);
87
+ });
88
+ },
89
+ retryNotificationWebhookJob(environmentId, organizationId, id, now) {
90
+ return tx(async (sql) => {
91
+ const result = await sql.query(`UPDATE app_notification_webhook_jobs job
92
+ SET status = 'queued', next_attempt_at = $4::timestamptz, updated_at = $4::timestamptz
93
+ WHERE job.environment_id = $1 AND job.organization_id = $2 AND job.id = $3 AND ${canRetry}
94
+ RETURNING job.id`, [environmentId, organizationId, id, now]);
95
+ return result.rows.length > 0;
96
+ });
97
+ },
98
+ pruneNotificationWebhookJobs(now, retainAfter) {
99
+ return tx(async (sql) => {
100
+ await sql.query(`UPDATE app_notification_webhook_jobs
101
+ SET body_enc = NULL, status = 'expired', failure_code = 'EXPIRED', lease_token = NULL, leased_until = NULL,
102
+ next_attempt_at = NULL, updated_at = $1::timestamptz
103
+ WHERE body_enc IS NOT NULL AND expires_at <= $1::timestamptz AND (leased_until IS NULL OR leased_until <= $1::timestamptz)`, [now]);
104
+ await sql.query("DELETE FROM app_notification_webhook_jobs WHERE body_enc IS NULL AND updated_at < $1::timestamptz", [retainAfter]);
105
+ });
106
+ },
107
+ };
108
+ }
109
+ //# sourceMappingURL=notification-webhook-sql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-webhook-sql.js","sourceRoot":"","sources":["../src/notification-webhook-sql.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAY,MAAM,WAAW,CAAC;AAE3C,MAAM,WAAW,GAAG;;;;;;CAMnB,CAAC;AAEF,MAAM,QAAQ,GAAG;yBACQ,WAAW;;;0FAGsD,CAAC;AAE3F,SAAS,YAAY,CAAC,GAAQ,EAAE,GAAW;IACzC,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,OAAO,CAAC,GAAQ;IACvB,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;QAC5G,MAAM,EAAE,GAAG,CAA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AE;gBACtB,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC;;2FAEoD,QAAQ;2BACxE,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC;QACD,4BAA4B,CAAC,GAAG,EAAE,WAAW;YAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBACtB,MAAM,GAAG,CAAC,KAAK,CAAC;;;qIAG6G,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;gBACtI,MAAM,GAAG,CAAC,KAAK,CAAC,mGAAmG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;YACtI,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/rows.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { HostedHumanSelection, HostedHumanSession } from "@x12i/keyrox-store";
2
+ import type { Agent, AgentExecution, AgentInstance, Application, ApplicationStaffAccess, TrashedApplication, AppEnvironment, AppTokenRecord, AuditEvent, AuthorizationRequest, ClientApp, DelegationGrant, DeniedJti, EmailChallenge, IdempotencyRecord, Invite, HostedHumanClient, HostedHumanCode, LongLivedToken, Membership, Org, ProviderConnection, RefreshToken, Session, User, WorkloadTrust } from "@x12i/keyrox-types";
3
+ export type Row = Record<string, unknown>;
4
+ export declare function time(row: Row, key: string): string;
5
+ export declare function userOf(row: Row): User;
6
+ export declare function orgOf(row: Row): Org;
7
+ export declare function membershipOf(row: Row): Membership;
8
+ export declare function challengeOf(row: Row): EmailChallenge;
9
+ export declare function inviteOf(row: Row): Invite;
10
+ export declare function sessionOf(row: Row): Session;
11
+ export declare function clientOf(row: Row): ClientApp;
12
+ export declare function agentOf(row: Row): Agent;
13
+ export declare function authorizationOf(row: Row): AuthorizationRequest;
14
+ export declare function grantOf(row: Row): DelegationGrant;
15
+ export declare function longTokenOf(row: Row): LongLivedToken;
16
+ export declare function hostedHumanSessionOf(row: Row): HostedHumanSession;
17
+ export declare function hostedHumanSelectionOf(row: Row): HostedHumanSelection;
18
+ export declare function refreshOf(row: Row): RefreshToken;
19
+ export declare function instanceOf(row: Row): AgentInstance;
20
+ export declare function executionOf(row: Row): AgentExecution;
21
+ export declare function providerOf(row: Row): ProviderConnection;
22
+ export declare function trustOf(row: Row): WorkloadTrust;
23
+ export declare function auditOf(row: Row): AuditEvent;
24
+ export declare function deniedOf(row: Row): DeniedJti;
25
+ export declare function applicationOf(row: Row): Application;
26
+ export declare function trashedApplicationOf(row: Row): TrashedApplication;
27
+ export declare function notificationSettingsOf(row: Row): import("@x12i/keyrox-types").AppNotificationSettings;
28
+ export declare function notificationWebhookOf(row: Row): import("@x12i/keyrox-types").AppNotificationWebhook;
29
+ export declare function environmentOf(row: Row): AppEnvironment;
30
+ export declare function applicationStaffAccessOf(row: Row): ApplicationStaffAccess;
31
+ export declare function appTokenOf(row: Row): AppTokenRecord;
32
+ export declare function idempotencyOf(row: Row): IdempotencyRecord;
33
+ export declare function platformSignInOf(row: Row): import("@x12i/keyrox-types").PlatformSignIn;
34
+ export declare function accountIdentityOf(row: Row): import("@x12i/keyrox-types").AccountIdentity;
35
+ export declare function accountSsoLoginOf(row: Row): import("@x12i/keyrox-types").AccountSsoLogin;
36
+ export declare function accountSsoProfileOf(row: Row): import("@x12i/keyrox-types").AccountSsoProfile;
37
+ export declare function accountHandoffOf(row: Row): import("@x12i/keyrox-types").AccountHandoff;
38
+ export declare function cliLoginCodeOf(row: Row): import("@x12i/keyrox-types").CliLoginCode;
39
+ export declare function signInOf(row: Row): import("@x12i/keyrox-types").SignInConnection;
40
+ export declare function ssoLoginOf(row: Row): import("@x12i/keyrox-types").SsoLogin;
41
+ export declare function hostedEmailCodeOf(row: Row): import("@x12i/keyrox-types").HostedEmailCode;
42
+ export declare function hostedSsoProfileOf(row: Row): import("@x12i/keyrox-types").HostedSsoProfile;
43
+ export declare function hostedSsoIdentityOf(row: Row): import("@x12i/keyrox-types").HostedSsoIdentity;
44
+ export declare function ssoExchangeOf(row: Row): import("@x12i/keyrox-types").SsoExchange;
45
+ export declare function hostedHumanClientOf(row: Row): HostedHumanClient;
46
+ export declare function hostedHumanCodeOf(row: Row): HostedHumanCode;
47
+ export declare function serviceCredentialOf(row: Row): import("@x12i/keyrox-types").ServiceCredential;
48
+ export declare function principalOf(row: Row): import("@x12i/keyrox-types").WorkloadPrincipal;
49
+ export declare function workloadCredentialOf(row: Row): import("@x12i/keyrox-types").WorkloadCredential;
50
+ export declare function audienceOf(row: Row): import("@x12i/keyrox-types").Audience;
51
+ export declare function roleOf(row: Row): import("@x12i/keyrox-types").RoleDefinition;
52
+ export declare function assignmentOf(row: Row): import("@x12i/keyrox-types").RoleAssignment;
53
+ export declare function gatewayRouteOf(row: Row): import("@x12i/keyrox-types").GatewayRoute;
54
+ //# sourceMappingURL=rows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EACV,KAAK,EACL,cAAc,EACd,aAAa,EACb,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EAEd,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,eAAe,EACf,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,MAAM,EAEN,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,UAAU,EACV,GAAG,EACH,kBAAkB,EAClB,YAAY,EACZ,OAAO,EACP,IAAI,EACJ,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAmB1C,wBAAgB,IAAI,C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1
+ function value(row, key) {
2
+ return row[key];
3
+ }
4
+ function text(row, key) {
5
+ const item = value(row, key);
6
+ if (typeof item !== "string")
7
+ throw new Error(`Expected text ${key}.`);
8
+ return item;
9
+ }
10
+ function textOrNull(row, key) {
11
+ const item = value(row, key);
12
+ if (item == null)
13
+ return null;
14
+ if (typeof item !== "string")
15
+ throw new Error(`Expected text ${key}.`);
16
+ return item;
17
+ }
18
+ export function time(row, key) {
19
+ const item = value(row, key);
20
+ if (item instanceof Date)
21
+ return item.toISOString();
22
+ if (typeof item === "string")
23
+ return new Date(item).toISOString();
24
+ throw new Error(`Expected timestamp ${key}.`);
25
+ }
26
+ function timeOrNull(row, key) {
27
+ return value(row, key) == null ? null : time(row, key);
28
+ }
29
+ function flag(row, key) {
30
+ const item = value(row, key);
31
+ if (typeof item !== "boolean")
32
+ throw new Error(`Expected boolean ${key}.`);
33
+ return item;
34
+ }
35
+ function integerOrNull(row, key) {
36
+ return value(row, key) == null ? null : integer(row, key);
37
+ }
38
+ function jsonValue(row, key) {
39
+ const item = value(row, key);
40
+ if (typeof item === "string")
41
+ return JSON.parse(item);
42
+ if (item && typeof item === "object")
43
+ return item;
44
+ throw new Error(`Expected json ${key}.`);
45
+ }
46
+ function integer(row, key) {
47
+ const item = value(row, key);
48
+ if (typeof item === "number")
49
+ return item;
50
+ if (typeof item === "bigint")
51
+ return Number(item);
52
+ if (typeof item === "string" && item !== "")
53
+ return Number(item);
54
+ throw new Error(`Expected number ${key}.`);
55
+ }
56
+ function texts(row, key) {
57
+ const item = value(row, key);
58
+ if (!Array.isArray(item))
59
+ throw new Error(`Expected text[] ${key}.`);
60
+ return item.map(String);
61
+ }
62
+ export function userOf(row) {
63
+ return {
64
+ id: text(row, "id"), email: text(row, "email"), passwordHash: textOrNull(row, "password_hash"), displayName: text(row, "display_name"),
65
+ emailVerifiedAt: timeOrNull(row, "email_verified_at"), disabledAt: timeOrNull(row, "disabled_at"), createdAt: time(row, "created_at"),
66
+ lastOrgId: textOrNull(row, "last_org_id"),
67
+ };
68
+ }
69
+ export function orgOf(row) {
70
+ return {
71
+ id: text(row, "id"), slug: text(row, "slug"), name: text(row, "name"), personal: flag(row, "personal"), logoUrl: textOrNull(row, "logo_url"), createdAt: time(row, "created_at"),
72
+ policy: {
73
+ allowNeverExpire: flag(row, "allow_never_expire"), allowDeviceFlow: flag(row, "allow_device_flow"),
74
+ grantMaxDays: integer(row, "grant_max_days"), version: integer(row, "policy_version"),
75
+ },
76
+ };
77
+ }
78
+ export function membershipOf(row) {
79
+ return {
80
+ id: text(row, "id"), orgId: text(row, "org_id"), userId: text(row, "user_id"), role: text(row, "role"),
81
+ actions: texts(row, "actions"), productionAccess: flag(row, "production_access") || text(row, "role") === "owner", createdAt: time(row, "created_at"),
82
+ };
83
+ }
84
+ export function challengeOf(row) {
85
+ return {
86
+ id: text(row, "id"), userId: text(row, "user_id"), purpose: text(row, "purpose"), tokenHash: text(row, "token_hash"),
87
+ expiresAt: time(row, "expires_at"), usedAt: timeOrNull(row, "used_at"), createdAt: time(row, "created_at"),
88
+ };
89
+ }
90
+ export function inviteOf(row) {
91
+ return {
92
+ id: text(row, "id"), orgId: text(row, "org_id"), email: text(row, "email"), role: text(row, "role"),
93
+ actions: texts(row, "actions"), tokenHash: text(row, "token_hash"), invitedBy: text(row, "invited_by"),
94
+ expiresAt: time(row, "expires_at"), acceptedAt: timeOrNull(row, "accepted_at"), createdAt: time(row, "created_at"),
95
+ productionAccess: flag(row, "production_access"),
96
+ revokedAt: timeOrNull(row, "revoked_at"), lastMailRequestedAt: timeOrNull(row, "last_mail_requested_at"),
97
+ };
98
+ }
99
+ export function sessionOf(row) {
100
+ return {
101
+ id: text(row, "id"), userId: text(row, "user_id"), orgId: text(row, "org_id"), secretHash: text(row, "secret_hash"),
102
+ csrf: text(row, "csrf"), expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
103
+ };
104
+ }
105
+ export function clientOf(row) {
106
+ return {
107
+ id: text(row, "id"), name: text(row, "name"), authMethod: text(row, "auth_method"),
108
+ secretHash: textOrNull(row, "secret_hash"), redirectUris: texts(row, "redirect_uris"), createdAt: time(row, "created_at"),
109
+ };
110
+ }
111
+ export function agentOf(row) {
112
+ return {
113
+ id: text(row, "id"), name: text(row, "name"), clientId: text(row, "client_id"), ownerUserId: text(row, "owner_user_id"),
114
+ orgId: text(row, "org_id"), suspendedAt: timeOrNull(row, "suspended_at"), createdAt: time(row, "created_at"),
115
+ };
116
+ }
117
+ export function authorizationOf(row) {
118
+ return {
119
+ id: text(row, "id"), kind: text(row, "kind"), clientId: text(row, "client_id"),
120
+ redirectUri: textOrNull(row, "redirect_uri"), codeChallenge: textOrNull(row, "code_challenge"), audience: text(row, "audience"),
121
+ actions: texts(row, "actions"), resources: texts(row, "resources"), state: textOrNull(row, "state"), orgId: textOrNull(row, "org_id"),
122
+ userId: textOrNull(row, "user_id"), status: text(row, "status"), codeHash: textOrNull(row, "code_hash"),
123
+ deviceCodeHash: textOrNull(row, "device_code_hash"), userCodeHash: textOrNull(row, "user_code_hash"), grantId: textOrNull(row, "grant_id"),
124
+ agentId: textOrNull(row, "agent_id"), intervalSeconds: integer(row, "interval_seconds"), lastPollAt: timeOrNull(row, "last_poll_at"),
125
+ expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
126
+ };
127
+ }
128
+ export function grantOf(row) {
129
+ return {
130
+ id: text(row, "id"), userId: text(row, "user_id"), orgId: text(row, "org_id"), clientId: text(row, "client_id"), agentId: text(row, "agent_id"),
131
+ audience: text(row, "audience"), actions: texts(row, "actions"), resources: texts(row, "resources"), jkt: textOrNull(row, "jkt"),
132
+ approvalRequestId: text(row, "approval_request_id"), policyVersion: integer(row, "policy_version"), createdAt: time(row, "created_at"),
133
+ expiresAt: time(row, "expires_at"), revokedAt: timeOrNull(row, "revoked_at"),
134
+ };
135
+ }
136
+ export function longTokenOf(row) {
137
+ return {
138
+ id: text(row, "id"), prefix: text(row, "prefix"), hash: text(row, "hash"), kind: text(row, "kind"),
139
+ name: text(row, "name"), userId: text(row, "user_id"), orgId: text(row, "org_id"), audience: text(row, "audience"),
140
+ actions: texts(row, "actions"), resources: texts(row, "resources"), grantId: textOrNull(row, "grant_id"), agentId: textOrNull(row, "agent_id"),
141
+ expiresAt: timeOrNull(row, "expires_at"), revokedAt: timeOrNull(row, "revoked_at"), createdAt: time(row, "created_at"), lastUsedAt: timeOrNull(row, "last_used_at"),
142
+ };
143
+ }
144
+ export function hostedHumanSessionOf(row) {
145
+ return {
146
+ id: text(row, "id"), clientId: text(row, "client_id"), appId: text(row, "app_id"),
147
+ environmentId: text(row, "environment_id"), subjectId: text(row, "subject_id"), audience: text(row, "audience"),
148
+ organizationId: textOrNull(row, "organization_id"), workspaceId: textOrNull(row, "workspace_id"),
149
+ createdAt: time(row, "created_at"), expiresAt: time(row, "expires_at"), revokedAt: timeOrNull(row, "revoked_at"),
150
+ };
151
+ }
152
+ export function hostedHumanSelectionOf(row) {
153
+ return {
154
+ tokenHash: text(row, "token_hash"), clientId: text(row, "client_id"), appId: text(row, "app_id"),
155
+ environmentId: text(row, "environment_id"), subjectId: text(row, "subject_id"),
156
+ createdAt: time(row, "created_at"), expiresAt: time(row, "expires_at"),
157
+ };
158
+ }
159
+ export function refreshOf(row) {
160
+ return {
161
+ id: text(row, "id"), hash: text(row, "hash"), familyId: text(row, "family_id"), grantId: textOrNull(row, "grant_id"),
162
+ clientId: text(row, "client_id"), userId: text(row, "user_id"), orgId: text(row, "org_id"), audience: text(row, "audience"),
163
+ actions: texts(row, "actions"), resources: texts(row, "resources"), agentId: textOrNull(row, "agent_id"), expiresAt: time(row, "expires_at"),
164
+ rotatedAt: timeOrNull(row, "rotated_at"), revokedAt: timeOrNull(row, "revoked_at"), createdAt: time(row, "created_at"),
165
+ };
166
+ }
167
+ export function instanceOf(row) {
168
+ return {
169
+ id: text(row, "id"), agentId: text(row, "agent_id"), grantId: text(row, "grant_id"), jkt: textOrNull(row, "jkt"),
170
+ createdAt: time(row, "created_at"), lastSeenAt: time(row, "last_seen_at"),
171
+ };
172
+ }
173
+ export function executionOf(row) {
174
+ return {
175
+ id: text(row, "id"), agentId: text(row, "agent_id"), instanceId: textOrNull(row, "instance_id"), grantId: textOrNull(row, "grant_id"),
176
+ trace: text(row, "trace"), createdAt: time(row, "created_at"),
177
+ };
178
+ }
179
+ export function providerOf(row) {
180
+ return {
181
+ id: text(row, "id"), userId: text(row, "user_id"), orgId: text(row, "org_id"), provider: text(row, "provider"),
182
+ accountLabel: text(row, "account_label"), scopes: texts(row, "scopes"), accessTokenEnc: text(row, "access_token_enc"),
183
+ refreshTokenEnc: textOrNull(row, "refresh_token_enc"), baseUrl: text(row, "base_url"), revokedAt: timeOrNull(row, "revoked_at"),
184
+ createdAt: time(row, "created_at"),
185
+ };
186
+ }
187
+ export function trustOf(row) {
188
+ const jwks = value(row, "jwks");
189
+ return {
190
+ id: text(row, "id"), name: text(row, "name"), issuer: text(row, "issuer"), audience: text(row, "audience"), tenant: text(row, "tenant"),
191
+ orgId: text(row, "org_id"), actions: texts(row, "actions"), jwks: Array.isArray(jwks) ? jwks : [],
192
+ disabledAt: timeOrNull(row, "disabled_at"), createdAt: time(row, "created_at"),
193
+ };
194
+ }
195
+ export function auditOf(row) {
196
+ const actorServiceId = textOrNull(row, "actor_service_id");
197
+ return {
198
+ id: text(row, "id"), at: time(row, "at"), orgId: textOrNull(row, "org_id"), actorUserId: textOrNull(row, "actor_user_id"),
199
+ ...(actorServiceId === null ? {} : { actorServiceId }),
200
+ agentId: textOrNull(row, "agent_id"), audience: textOrNull(row, "audience"), action: text(row, "action"),
201
+ decision: text(row, "decision"), target: text(row, "target"), detail: text(row, "detail"),
202
+ };
203
+ }
204
+ export function deniedOf(row) {
205
+ return { id: text(row, "id"), exp: integer(row, "exp") };
206
+ }
207
+ function statusOf(row) {
208
+ const status = text(row, "status");
209
+ if (status !== "active" && status !== "disabled")
210
+ throw new Error("Expected status.");
211
+ return status;
212
+ }
213
+ export function applicationOf(row) {
214
+ const audience = text(row, "signup_audience");
215
+ return {
216
+ id: text(row, "id"), orgId: text(row, "org_id"), title: text(row, "title"), description: text(row, "description"), status: statusOf(row),
217
+ allowedScopes: texts(row, "allowed_scopes"), allowedFeatures: texts(row, "allowed_features"),
218
+ productName: text(row, "product_name") || text(row, "title"), logoUrl: textOrNull(row, "logo_url"), accentColor: textOrNull(row, "accent_color"),
219
+ signupMode: text(row, "signup_mode") === "waiting-list" ? "waiting-list" : "open",
220
+ waitlistQuestions: texts(row, "waitlist_questions"),
221
+ waitlistQuestionDefinitions: row.waitlist_question_definitions == null ? null
222
+ : jsonValue(row, "waitlist_question_definitions"),
223
+ waitlistQuestionLayout: text(row, "waitlist_question_layout") === "wizard" ? "wizard" : "form",
224
+ allowRegistrationWithoutPersonalOrg: flag(row, "allow_without_personal_org"),
225
+ signupAudience: audience === "business-or-sso" || audience === "sso-only" ? audience : "any-email",
226
+ signupSsoProviders: texts(row, "signup_sso_providers"),
227
+ signupOrganization: text(row, "signup_organization") === "optional" ? "optional" : "required",
228
+ managedSignIn: flag(row, "managed_sign_in"),
229
+ emailCodeSignIn: flag(row, "email_code_sign_in"),
230
+ authCopy: jsonValue(row, "auth_copy"),
231
+ directoryModel: text(row, "directory_model"),
232
+ directoryLabels: jsonValue(row, "directory_labels"),
233
+ onboarding: jsonValue(row, "onboarding"),
234
+ createdAt: time(row, "created_at"), updatedAt: time(row, "updated_at"),
235
+ };
236
+ }
237
+ export function trashedApplicationOf(row) {
238
+ return { ...applicationOf(row), trashedAt: time(row, "trashed_at") };
239
+ }
240
+ export function notificationSettingsOf(row) {
241
+ const delivery = text(row, "delivery");
242
+ if (delivery !== "keyrox" && delivery !== "both" && delivery !== "webhook")
243
+ throw new Error("Invalid notification delivery.");
244
+ return {
245
+ environmentId: text(row, "environment_id"), appId: text(row, "app_id"), orgId: text(row, "org_id"), delivery,
246
+ templates: jsonValue(row, "templates"), updatedAt: time(row, "updated_at"),
247
+ };
248
+ }
249
+ export function notificationWebhookOf(row) {
250
+ return {
251
+ id: text(row, "id"), environmentId: text(row, "environment_id"), appId: text(row, "app_id"), orgId: text(row, "org_id"),
252
+ url: text(row, "url"), secretEnc: text(row, "secret_enc"), enabled: flag(row, "enabled"),
253
+ createdAt: time(row, "created_at"), updatedAt: time(row, "updated_at"),
254
+ };
255
+ }
256
+ export function environmentOf(row) {
257
+ return {
258
+ id: text(row, "id"), appId: text(row, "app_id"), orgId: text(row, "org_id"), name: text(row, "name"), title: text(row, "title"), status: statusOf(row),
259
+ secretEnc: text(row, "secret_enc"), secretHash: text(row, "secret_hash"), keyVersion: integer(row, "key_version"),
260
+ previousSecretEnc: textOrNull(row, "previous_secret_enc"), previousSecretHash: textOrNull(row, "previous_secret_hash"),
261
+ previousKeyVersion: integerOrNull(row, "previous_key_version"), previousKeyExpiresAt: timeOrNull(row, "previous_key_expires_at"),
262
+ createdAt: time(row, "created_at"), updatedAt: time(row, "updated_at"),
263
+ };
264
+ }
265
+ export function applicationStaffAccessOf(row) {
266
+ const runtime = text(row, "runtime");
267
+ if (runtime !== "none" && runtime !== "read" && runtime !== "manage")
268
+ throw new Error("Invalid application staff runtime access.");
269
+ return {
270
+ id: text(row, "id"), orgId: text(row, "org_id"), appId: text(row, "app_id"), environmentId: text(row, "environment_id"),
271
+ userId: text(row, "user_id"), design: flag(row, "design"), runtime, createdAt: time(row, "created_at"), updatedAt: time(row, "updated_at"),
272
+ };
273
+ }
274
+ export function appTokenOf(row) {
275
+ return {
276
+ id: text(row, "id"), appId: text(row, "app_id"), environmentId: text(row, "environment_id"), orgId: text(row, "org_id"), ownerIdentityId: text(row, "owner_identity_id"),
277
+ identityType: text(row, "identity_type"), payload: jsonValue(row, "payload"),
278
+ encrypted: flag(row, "encrypted"), revokedAt: timeOrNull(row, "revoked_at"), expiresAt: timeOrNull(row, "expires_at"), createdAt: time(row, "created_at"),
279
+ };
280
+ }
281
+ export function idempotencyOf(row) {
282
+ return { id: text(row, "id"), requestHash: text(row, "request_hash"), status: integer(row, "status"), body: text(row, "body"), createdAt: time(row, "created_at") };
283
+ }
284
+ export function platformSignInOf(row) {
285
+ return {
286
+ id: text(row, "id"), provider: text(row, "provider"),
287
+ clientId: text(row, "client_id"), clientSecretEnc: text(row, "client_secret_enc"), directoryId: textOrNull(row, "directory_id"),
288
+ issuer: textOrNull(row, "issuer"), createdAt: time(row, "created_at"), managedForApps: flag(row, "managed_for_apps"),
289
+ };
290
+ }
291
+ export function accountIdentityOf(row) {
292
+ return {
293
+ id: text(row, "id"), userId: text(row, "user_id"), provider: text(row, "provider"),
294
+ subject: text(row, "subject"), email: textOrNull(row, "email"), createdAt: time(row, "created_at"),
295
+ };
296
+ }
297
+ export function accountSsoLoginOf(row) {
298
+ return {
299
+ id: text(row, "id"), stateHash: text(row, "state_hash"), nonce: text(row, "nonce"), verifier: text(row, "verifier"),
300
+ provider: text(row, "provider"), nextPath: textOrNull(row, "next_path"),
301
+ linkUserId: textOrNull(row, "link_user_id"), linkSessionHash: textOrNull(row, "link_session_hash"),
302
+ expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
303
+ };
304
+ }
305
+ export function accountSsoProfileOf(row) {
306
+ return {
307
+ id: text(row, "id"), codeHash: text(row, "code_hash"), browserHash: text(row, "browser_hash"),
308
+ provider: text(row, "provider"),
309
+ connectionFingerprint: text(row, "connection_fingerprint"), subject: text(row, "subject"),
310
+ email: text(row, "email"), nextPath: textOrNull(row, "next_path"), expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
311
+ };
312
+ }
313
+ export function accountHandoffOf(row) {
314
+ return {
315
+ id: text(row, "id"), codeHash: text(row, "code_hash"), sessionToken: text(row, "session_token"),
316
+ expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
317
+ };
318
+ }
319
+ export function cliLoginCodeOf(row) {
320
+ return {
321
+ codeHash: text(row, "code_hash"), requestHash: text(row, "request_hash"),
322
+ codeChallenge: text(row, "code_challenge"), redirectUri: text(row, "redirect_uri"),
323
+ userId: text(row, "user_id"), orgId: text(row, "org_id"), browserSessionHash: text(row, "browser_session_hash"),
324
+ expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"), consumedAt: timeOrNull(row, "consumed_at"),
325
+ };
326
+ }
327
+ export function signInOf(row) {
328
+ const legacyConnectionId = textOrNull(row, "legacy_connection_id");
329
+ return {
330
+ id: text(row, "id"), appId: text(row, "app_id"), orgId: text(row, "org_id"), provider: text(row, "provider"),
331
+ clientId: text(row, "client_id"), clientSecretEnc: text(row, "client_secret_enc"), directoryId: textOrNull(row, "directory_id"),
332
+ issuer: textOrNull(row, "issuer"), createdAt: time(row, "created_at"), ...(legacyConnectionId ? { legacyConnectionId } : {}),
333
+ };
334
+ }
335
+ export function ssoLoginOf(row) {
336
+ return {
337
+ id: text(row, "id"), stateHash: text(row, "state_hash"), nonce: text(row, "nonce"), verifier: text(row, "verifier"),
338
+ appId: text(row, "app_id"), environmentId: text(row, "environment_id"), orgId: text(row, "org_id"),
339
+ provider: text(row, "provider"), redirectUri: text(row, "redirect_uri"),
340
+ appState: textOrNull(row, "app_state"), connectionAuthority: textOrNull(row, "connection_authority"),
341
+ ...(row.human_binding ? { humanBinding: row.human_binding } : {}),
342
+ ...(flag(row, "waitlist_in_app") ? { waitlistInApp: true } : {}),
343
+ ...(textOrNull(row, "invitation_token_hash") ? { invitationTokenHash: textOrNull(row, "invitation_token_hash") } : {}),
344
+ expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
345
+ };
346
+ }
347
+ export function hostedEmailCodeOf(row) {
348
+ return {
349
+ id: text(row, "id"), appId: text(row, "app_id"), environmentId: text(row, "environment_id"), email: text(row, "email"),
350
+ challengeHash: text(row, "challenge_hash"), codeHash: text(row, "code_hash"),
351
+ createdAt: time(row, "created_at"), expiresAt: time(row, "expires_at"),
352
+ };
353
+ }
354
+ export function hostedSsoProfileOf(row) {
355
+ const displayName = textOrNull(row, "display_name");
356
+ const connectionFingerprint = textOrNull(row, "connection_fingerprint");
357
+ return {
358
+ id: text(row, "id"), challengeHash: text(row, "challenge_hash"), browserHash: text(row, "browser_hash"),
359
+ appId: text(row, "app_id"), environmentId: text(row, "environment_id"), orgId: text(row, "org_id"),
360
+ provider: text(row, "provider"), authority: text(row, "authority"),
361
+ subject: text(row, "subject"), email: textOrNull(row, "email"), redirectUri: text(row, "redirect_uri"),
362
+ ...(row.human_binding ? { humanBinding: row.human_binding } : {}),
363
+ ...(displayName !== null ? { displayName } : {}),
364
+ ...(connectionFingerprint !== null ? { connectionFingerprint } : {}),
365
+ ...(flag(row, "waitlist_in_app") ? { waitlistInApp: true } : {}),
366
+ appState: textOrNull(row, "app_state"), expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
367
+ };
368
+ }
369
+ export function hostedSsoIdentityOf(row) {
370
+ return { environmentId: text(row, "environment_id"), authority: text(row, "authority"), subject: text(row, "subject"), identityId: text(row, "identity_id") };
371
+ }
372
+ export function ssoExchangeOf(row) {
373
+ const redirectUri = textOrNull(row, "redirect_uri");
374
+ return {
375
+ id: text(row, "id"), codeHash: text(row, "code_hash"), appId: text(row, "app_id"), environmentId: text(row, "environment_id"),
376
+ ...(redirectUri === null ? {} : { redirectUri }),
377
+ token: text(row, "token"), tokenId: text(row, "token_id"), subject: text(row, "subject"),
378
+ provider: text(row, "provider"), expiresAt: time(row, "expires_at"), createdAt: time(row, "created_at"),
379
+ };
380
+ }
381
+ export function hostedHumanClientOf(row) {
382
+ return {
383
+ id: text(row, "id"), appId: text(row, "app_id"), environmentId: text(row, "environment_id"), orgId: text(row, "org_id"),
384
+ name: text(row, "name"), redirectUri: text(row, "redirect_uri"), audience: text(row, "audience"),
385
+ secretHash: text(row, "secret_hash"), createdAt: time(row, "created_at"), revokedAt: timeOrNull(row, "revoked_at"),
386
+ };
387
+ }
388
+ export function hostedHumanCodeOf(row) {
389
+ return {
390
+ codeHash: text(row, "code_hash"), appId: text(row, "app_id"), environmentId: text(row, "environment_id"), orgId: text(row, "org_id"),
391
+ clientId: text(row, "client_id"), redirectUri: text(row, "redirect_uri"), codeChallenge: text(row, "code_challenge"),
392
+ identityId: text(row, "identity_id"), provider: text(row, "provider"),
393
+ createdAt: time(row, "created_at"), expiresAt: time(row, "expires_at"),
394
+ };
395
+ }
396
+ export function serviceCredentialOf(row) {
397
+ return {
398
+ id: text(row, "id"), orgId: text(row, "org_id"), name: text(row, "name"), secretHash: text(row, "secret_hash"),
399
+ appIds: texts(row, "app_ids"), permissions: texts(row, "permissions"), revokedAt: timeOrNull(row, "revoked_at"), createdAt: time(row, "created_at"),
400
+ };
401
+ }
402
+ export function principalOf(row) {
403
+ return { id: text(row, "id"), orgId: text(row, "org_id"), name: text(row, "name"), clientId: text(row, "client_id"), enabled: flag(row, "enabled"), createdAt: time(row, "created_at") };
404
+ }
405
+ export function workloadCredentialOf(row) {
406
+ return {
407
+ id: text(row, "id"), principalId: text(row, "principal_id"), orgId: text(row, "org_id"), kind: text(row, "kind"),
408
+ secretHash: textOrNull(row, "secret_hash"), jwks: jsonValue(row, "jwks"), createdAt: time(row, "created_at"),
409
+ };
410
+ }
411
+ export function audienceOf(row) {
412
+ return { id: text(row, "id"), orgId: text(row, "org_id"), name: text(row, "name"), identifier: text(row, "identifier"), appId: textOrNull(row, "app_id"), createdAt: time(row, "created_at") };
413
+ }
414
+ export function roleOf(row) {
415
+ return { id: text(row, "id"), orgId: text(row, "org_id"), name: text(row, "name"), actions: texts(row, "actions"), createdAt: time(row, "created_at") };
416
+ }
417
+ export function assignmentOf(row) {
418
+ return { id: text(row, "id"), orgId: text(row, "org_id"), principalId: text(row, "principal_id"), roleId: text(row, "role_id"), scope: text(row, "scope"), createdAt: time(row, "created_at") };
419
+ }
420
+ export function gatewayRouteOf(row) {
421
+ return {
422
+ id: text(row, "id"), orgId: text(row, "org_id"), audienceId: text(row, "audience_id"), method: text(row, "method"), path: text(row, "path"),
423
+ dataAction: text(row, "data_action"), resource: text(row, "resource"), createdAt: time(row, "created_at"),
424
+ };
425
+ }
426
+ //# sourceMappingURL=rows.js.map