@arbidocs/sdk 0.4.70 → 0.4.72

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.cjs CHANGED
@@ -6479,6 +6479,76 @@ async function requestDeletion(arbi) {
6479
6479
  return requireData(await arbi.fetch.POST("/v1/user/request-deletion"), "Failed to delete account");
6480
6480
  }
6481
6481
 
6482
+ // src/operations/identity.ts
6483
+ var identity_exports = {};
6484
+ __export(identity_exports, {
6485
+ acceptName: () => acceptName,
6486
+ getStatus: () => getStatus,
6487
+ identityErrorCode: () => identityErrorCode,
6488
+ purchase: () => purchase,
6489
+ refresh: () => refresh,
6490
+ remove: () => remove,
6491
+ startSession: () => startSession
6492
+ });
6493
+ function refusal(apiError) {
6494
+ const detail = apiError?.detail;
6495
+ if (typeof detail === "string") return { message: detail };
6496
+ if (detail && typeof detail === "object" && !Array.isArray(detail)) {
6497
+ const { code, message } = detail;
6498
+ return {
6499
+ code: typeof code === "string" ? code : void 0,
6500
+ message: typeof message === "string" ? message : void 0
6501
+ };
6502
+ }
6503
+ return {};
6504
+ }
6505
+ function identityErrorCode(error) {
6506
+ return error instanceof ArbiApiError ? refusal(error.apiError).code : void 0;
6507
+ }
6508
+ function unwrap(result, fallback) {
6509
+ if (result.error || result.data === void 0) {
6510
+ throw new ArbiApiError(
6511
+ refusal(result.error).message ?? fallback,
6512
+ result.error,
6513
+ result.response?.status
6514
+ );
6515
+ }
6516
+ return result.data;
6517
+ }
6518
+ async function getStatus(arbi) {
6519
+ return unwrap(await arbi.fetch.GET("/v1/user/identity"), "Failed to load identity verification");
6520
+ }
6521
+ async function purchase(arbi, projectExtId) {
6522
+ return unwrap(
6523
+ await arbi.fetch.POST("/v1/user/identity/purchase", {
6524
+ body: projectExtId ? { project_ext_id: projectExtId } : {}
6525
+ }),
6526
+ "Payment could not be completed"
6527
+ );
6528
+ }
6529
+ async function startSession(arbi) {
6530
+ const data = unwrap(
6531
+ await arbi.fetch.POST("/v1/user/identity/session"),
6532
+ "Could not start identity verification"
6533
+ );
6534
+ return data.url;
6535
+ }
6536
+ async function refresh(arbi) {
6537
+ return unwrap(
6538
+ await arbi.fetch.POST("/v1/user/identity/refresh"),
6539
+ "Could not read the verification result"
6540
+ );
6541
+ }
6542
+ async function acceptName(arbi) {
6543
+ return unwrap(
6544
+ await arbi.fetch.POST("/v1/user/identity/accept-name"),
6545
+ "Could not change your name"
6546
+ );
6547
+ }
6548
+ async function remove(arbi) {
6549
+ return unwrap(await arbi.fetch.DELETE("/v1/user/identity"), "Could not remove the verification");
6550
+ }
6551
+
6482
6552
  // src/operations/projects.ts
6483
6553
  var projects_exports = {};
6484
6554
  __export(projects_exports, {
@@ -6495,10 +6565,10 @@ __export(projects_exports, {
6495
6565
  async function listProjects(arbi) {
6496
6566
  return requireData(await arbi.fetch.GET("/v1/user/projects/"), "Failed to fetch projects");
6497
6567
  }
6498
- async function createProject(arbi, name) {
6568
+ async function createProject(arbi, name, plan = "free") {
6499
6569
  return requireData(
6500
6570
  await arbi.fetch.POST("/v1/user/projects/", {
6501
- body: { name }
6571
+ body: { name, plan }
6502
6572
  }),
6503
6573
  "Failed to create project"
6504
6574
  );
@@ -6750,10 +6820,18 @@ var Arbi = class {
6750
6820
  this.options = options;
6751
6821
  }
6752
6822
  // ── Lifecycle ───────────────────────────────────────────────────────────
6823
+ /**
6824
+ * The deployment domain the user's keys are derived for: `deploymentDomain` when given,
6825
+ * otherwise the hostname of `url`. Signing and password changes re-derive keys with it, so a
6826
+ * host that needs it (the document tools' e-signing) reads it here rather than recomputing it.
6827
+ */
6828
+ getDeploymentDomain() {
6829
+ return this.options.deploymentDomain ?? new URL(this.options.url).hostname;
6830
+ }
6753
6831
  /** Initialize the SDK client and sodium crypto. Called automatically by login(). */
6754
6832
  async init() {
6755
6833
  if (this.client) return this.client;
6756
- const domain = this.options.deploymentDomain ?? new URL(this.options.url).hostname;
6834
+ const domain = this.getDeploymentDomain();
6757
6835
  this.client = client.createArbiClient({
6758
6836
  baseUrl: this.options.url,
6759
6837
  deploymentDomain: domain,
@@ -7016,7 +7094,8 @@ var Arbi = class {
7016
7094
  ...this.userProfile,
7017
7095
  givenName: updated.given_name ?? this.userProfile.givenName,
7018
7096
  familyName: updated.family_name ?? null,
7019
- picture: updated.picture ?? null
7097
+ picture: updated.picture ?? null,
7098
+ isIdentityVerified: updated.is_identity_verified ?? false
7020
7099
  });
7021
7100
  }
7022
7101
  return updated;
@@ -7048,7 +7127,7 @@ var Arbi = class {
7048
7127
  { ...params, email, userExtId: lr2.userExtId },
7049
7128
  {
7050
7129
  fetchClient: client$1.fetch,
7051
- deploymentDomain: this.options.deploymentDomain ?? new URL(this.options.url).hostname
7130
+ deploymentDomain: this.getDeploymentDomain()
7052
7131
  }
7053
7132
  );
7054
7133
  this.loginResult = { ...lr2, signingPrivateKey: result.newSigningPrivateKey };
@@ -7061,6 +7140,49 @@ var Arbi = class {
7061
7140
  return result;
7062
7141
  }
7063
7142
  };
7143
+ // ── Identity verification ─────────────────────────────────────────────
7144
+ identity = {
7145
+ /** Whether the ID check is offered (Pro plans), its price, and where the user's check stands. */
7146
+ status: () => getStatus(this.requireClient()),
7147
+ /** Charge the one-time fee to an own Pro project; `requires_action` carries a payment URL. */
7148
+ purchase: (projectExtId) => purchase(this.requireClient(), projectExtId),
7149
+ /** The Didit session URL to run the web SDK on. */
7150
+ startSession: () => startSession(this.requireClient()),
7151
+ /** Read the decision of the open check; the profile follows a granted tick. */
7152
+ refresh: async () => {
7153
+ const status = await refresh(this.requireClient());
7154
+ this.syncIdentity(status);
7155
+ return status;
7156
+ },
7157
+ /** Take the name on the document as the account name; the profile follows. */
7158
+ acceptName: async () => {
7159
+ const client = this.requireClient();
7160
+ const offered = await getStatus(client);
7161
+ const status = await acceptName(client);
7162
+ if (this.userProfile && offered.document_given_name) {
7163
+ this.setUserProfile({
7164
+ ...this.userProfile,
7165
+ givenName: offered.document_given_name,
7166
+ familyName: offered.document_family_name ?? null,
7167
+ isIdentityVerified: status.verified
7168
+ });
7169
+ } else {
7170
+ this.syncIdentity(status);
7171
+ }
7172
+ return status;
7173
+ },
7174
+ /** Remove the tick and erase any open check. */
7175
+ remove: async () => {
7176
+ const status = await remove(this.requireClient());
7177
+ this.syncIdentity(status);
7178
+ return status;
7179
+ }
7180
+ };
7181
+ syncIdentity(status) {
7182
+ if (this.userProfile && this.userProfile.isIdentityVerified !== status.verified) {
7183
+ this.setUserProfile({ ...this.userProfile, isIdentityVerified: status.verified });
7184
+ }
7185
+ }
7064
7186
  // ── Workspaces ────────────────────────────────────────────────────────
7065
7187
  workspaces = {
7066
7188
  list: () => listWorkspaces(this.requireClient()),
@@ -8803,6 +8925,8 @@ exports.getErrorCode = getErrorCode;
8803
8925
  exports.getErrorMessage = getErrorMessage;
8804
8926
  exports.getRawWorkspaceKey = getRawWorkspaceKey;
8805
8927
  exports.health = health_exports;
8928
+ exports.identityErrorCode = identityErrorCode;
8929
+ exports.identityVerification = identity_exports;
8806
8930
  exports.listen = listen_exports;
8807
8931
  exports.mail = mail_exports;
8808
8932
  exports.mailNode = mail_node_exports;