@orangecheck/me-client 0.16.0 → 0.18.0

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.js CHANGED
@@ -444,11 +444,240 @@ function verify(envelope, config2, payment_amount_sats) {
444
444
  }
445
445
  var event = { fire, fireBatch, verify };
446
446
 
447
+ // src/templates.ts
448
+ var FIXED = (sats) => ({
449
+ kind: "fixed_sats",
450
+ sats
451
+ });
452
+ var PCT = (pct) => ({
453
+ kind: "percent_of_amount",
454
+ pct
455
+ });
456
+ var ARCHETYPE_TEMPLATES = [
457
+ {
458
+ id: "saas-paywall",
459
+ label: "SaaS \xB7 paywall",
460
+ summary: "Subscription product \xB7 users sign up, sign in, sometimes pay for premium tiers. Default cashback to encourage signup + retention.",
461
+ examples: ["Notion-like notes app", "Linear-like project tracker", "Figma-like editor"],
462
+ events: {
463
+ account_creation: {
464
+ enabled: true,
465
+ site_pays: FIXED(1300),
466
+ user_share_pct: 0.65
467
+ },
468
+ session_creation: {
469
+ enabled: true,
470
+ site_pays: FIXED(55),
471
+ user_share_pct: 0.65
472
+ },
473
+ payment_authorization: {
474
+ enabled: true,
475
+ site_pays: PCT(75e-4),
476
+ user_share_pct: 0.65
477
+ },
478
+ payment_method_connected: {
479
+ enabled: true,
480
+ site_pays: FIXED(320),
481
+ user_share_pct: 0.65
482
+ }
483
+ }
484
+ },
485
+ {
486
+ id: "marketplace",
487
+ label: "marketplace",
488
+ summary: "Two-sided marketplace \xB7 buyers + sellers transact. Heavy on payment_authorization and scoped_action_authorization for listings.",
489
+ examples: ["Stripe-like checkout", "Etsy-like marketplace", "Uber-like ride-hailing"],
490
+ events: {
491
+ account_creation: {
492
+ enabled: true,
493
+ site_pays: FIXED(1300),
494
+ user_share_pct: 0.65
495
+ },
496
+ session_creation: {
497
+ enabled: true,
498
+ site_pays: FIXED(55),
499
+ user_share_pct: 0.65
500
+ },
501
+ payment_authorization: {
502
+ enabled: true,
503
+ site_pays: PCT(75e-4),
504
+ user_share_pct: 0.65
505
+ },
506
+ scoped_action_authorization: {
507
+ enabled: true,
508
+ site_pays: FIXED(100),
509
+ user_share_pct: 0.65
510
+ },
511
+ payment_method_connected: {
512
+ enabled: true,
513
+ site_pays: FIXED(320),
514
+ user_share_pct: 0.65
515
+ },
516
+ attest_verification_at_gate: {
517
+ enabled: true,
518
+ site_pays: FIXED(280),
519
+ user_share_pct: 0.65
520
+ }
521
+ }
522
+ },
523
+ {
524
+ id: "content-platform",
525
+ label: "content platform",
526
+ summary: "User-generated content \xB7 posts, reviews, votes, comments. Each meaningful action is scoped_action_authorization; stamp_signing for credentialed reviews.",
527
+ examples: ["Reddit-like forum", "YouTube-like video host", "Substack-like publishing"],
528
+ events: {
529
+ account_creation: {
530
+ enabled: true,
531
+ site_pays: FIXED(1300),
532
+ user_share_pct: 0.7
533
+ },
534
+ session_creation: {
535
+ enabled: true,
536
+ site_pays: FIXED(55),
537
+ user_share_pct: 0.7
538
+ },
539
+ scoped_action_authorization: {
540
+ enabled: true,
541
+ site_pays: FIXED(100),
542
+ user_share_pct: 0.7
543
+ },
544
+ stamp_signing: {
545
+ enabled: true,
546
+ site_pays: FIXED(55),
547
+ user_share_pct: 0.7
548
+ }
549
+ }
550
+ },
551
+ {
552
+ id: "gaming",
553
+ label: "gaming",
554
+ summary: "Game with monetized actions \xB7 pledges + scoped actions are core. Higher cashback ratios reward in-game engagement.",
555
+ examples: [
556
+ "on-chain prediction markets",
557
+ "skill-staking tournaments",
558
+ "PvP wager games"
559
+ ],
560
+ events: {
561
+ account_creation: {
562
+ enabled: true,
563
+ site_pays: FIXED(1300),
564
+ user_share_pct: 0.7
565
+ },
566
+ session_creation: {
567
+ enabled: true,
568
+ site_pays: FIXED(55),
569
+ user_share_pct: 0.7
570
+ },
571
+ scoped_action_authorization: {
572
+ enabled: true,
573
+ site_pays: FIXED(100),
574
+ user_share_pct: 0.7
575
+ },
576
+ payment_authorization: {
577
+ enabled: true,
578
+ site_pays: PCT(5e-3),
579
+ user_share_pct: 0.7
580
+ },
581
+ pledge_resolution: {
582
+ enabled: true,
583
+ site_pays: PCT(0.01),
584
+ user_share_pct: 0.7
585
+ },
586
+ attest_verification_at_gate: {
587
+ enabled: true,
588
+ site_pays: FIXED(280),
589
+ user_share_pct: 0.7
590
+ }
591
+ }
592
+ },
593
+ {
594
+ id: "agent-only",
595
+ label: "agent-only",
596
+ summary: "AI-agent surface \xB7 oc-agent delegations are the primary auth pattern. Session_creation off (delegations replace sessions); agent_delegation_issued + scoped_action_authorization carry the activity.",
597
+ examples: [
598
+ "AI assistant calling APIs on user behalf",
599
+ "autonomous trading bot",
600
+ "agent-driven customer support"
601
+ ],
602
+ events: {
603
+ account_creation: {
604
+ enabled: true,
605
+ site_pays: FIXED(1300),
606
+ user_share_pct: 0.65
607
+ },
608
+ agent_delegation_issued: {
609
+ enabled: true,
610
+ site_pays: FIXED(320),
611
+ user_share_pct: 0.65
612
+ },
613
+ scoped_action_authorization: {
614
+ enabled: true,
615
+ site_pays: FIXED(100),
616
+ user_share_pct: 0.65
617
+ }
618
+ }
619
+ }
620
+ ];
621
+ var ARCHETYPES_BY_ID = Object.fromEntries(
622
+ ARCHETYPE_TEMPLATES.map((t) => [t.id, t])
623
+ );
624
+ var ALL_SUBTYPES = [
625
+ "account_creation",
626
+ "account_recovery",
627
+ "attest_bond_increased",
628
+ "payment_method_connected",
629
+ "agent_delegation_issued",
630
+ "recovery_method_updated",
631
+ "payment_authorization",
632
+ "scoped_action_authorization",
633
+ "attest_verification_at_gate",
634
+ "stamp_signing",
635
+ "pledge_resolution",
636
+ "session_creation"
637
+ ];
638
+ var DEFAULT_DISABLED = {
639
+ enabled: false,
640
+ site_pays: { kind: "fixed_sats", sats: 100 },
641
+ user_share_pct: 0.65
642
+ };
643
+ function fromTemplate(useCase, identity) {
644
+ const template = ARCHETYPES_BY_ID[useCase];
645
+ if (!template) {
646
+ throw new Error(
647
+ `oc.config.fromTemplate: unknown archetype "${useCase}". Valid: ${Object.keys(
648
+ ARCHETYPES_BY_ID
649
+ ).join(", ")}`
650
+ );
651
+ }
652
+ const events = {};
653
+ for (const sub of ALL_SUBTYPES) {
654
+ events[sub] = template.events[sub] ?? DEFAULT_DISABLED;
655
+ }
656
+ return {
657
+ project_key: identity.project_key,
658
+ domain: identity.domain,
659
+ display_name: identity.display_name,
660
+ updated_at: (/* @__PURE__ */ new Date()).toISOString(),
661
+ events
662
+ };
663
+ }
664
+ function getArchetypeTemplate(id) {
665
+ return ARCHETYPES_BY_ID[id];
666
+ }
667
+
447
668
  // src/config.ts
448
669
  function validate(cfg) {
449
670
  return validateIntegratorConfig(cfg);
450
671
  }
451
- var config = { validate };
672
+ var config = {
673
+ validate,
674
+ fromTemplate,
675
+ /** Look up a template's metadata · for rendering "you picked X"
676
+ * state and offering one-click swaps in your own UI. */
677
+ getArchetype: getArchetypeTemplate,
678
+ /** All available archetypes · render in a picker. */
679
+ archetypes: ARCHETYPE_TEMPLATES
680
+ };
452
681
 
453
682
  // node_modules/jose/dist/webapi/lib/buffer_utils.js
454
683
  new TextEncoder();
@@ -909,9 +1138,135 @@ async function scopes(verb, options) {
909
1138
  }
910
1139
  var family = { scopes };
911
1140
 
1141
+ // src/subtypes.ts
1142
+ var EVENT_SUBTYPES = {
1143
+ // ── Class A · durable state transitions ──
1144
+ account_creation: {
1145
+ id: "account_creation",
1146
+ class: "A",
1147
+ label: "account creation",
1148
+ fires_when: "a new oc identity creates a durable account record on your surface (first sign-in, profile row inserted)",
1149
+ example: "user signed up via email-OTP and your account row was inserted in your DB",
1150
+ common_use_cases: ["onboarding", "signup", "registration", "first-login"],
1151
+ typical_price_hint: "~1300 sats (~$1.24)"
1152
+ },
1153
+ account_recovery: {
1154
+ id: "account_recovery",
1155
+ class: "A",
1156
+ label: "account recovery",
1157
+ fires_when: "a user re-binds an existing account to a new device or recovery method",
1158
+ example: "user lost their device and recovered the account via email OTP + recovery code",
1159
+ common_use_cases: ["recovery", "device-rebind", "restore-access"],
1160
+ typical_price_hint: "~650 sats (~$0.62)"
1161
+ },
1162
+ attest_bond_increased: {
1163
+ id: "attest_bond_increased",
1164
+ class: "A",
1165
+ label: "attest bond increased",
1166
+ fires_when: "a user upgrades their bond size (locks more sats to attest_tier=bonded with higher cap)",
1167
+ example: "user moved from 10k-sat bond to 100k-sat bond to clear your higher-trust gate",
1168
+ common_use_cases: ["bond-upgrade", "tier-promotion", "sybil-resistance"],
1169
+ typical_price_hint: "~1600 sats (~$1.52) \xB7 OFF by default"
1170
+ },
1171
+ payment_method_connected: {
1172
+ id: "payment_method_connected",
1173
+ class: "A",
1174
+ label: "payment method connected",
1175
+ fires_when: "a user connects a Lightning address, BIP-322 wallet, or payment-routing channel to their account",
1176
+ example: "user pasted a lightning@address.com receive address into their profile",
1177
+ common_use_cases: ["payment-setup", "wallet-connect", "payout-config"],
1178
+ typical_price_hint: "~320 sats (~$0.30)"
1179
+ },
1180
+ agent_delegation_issued: {
1181
+ id: "agent_delegation_issued",
1182
+ class: "A",
1183
+ label: "agent delegation issued",
1184
+ fires_when: "a user signs an oc-agent delegation envelope authorizing an AI agent to act on their behalf",
1185
+ example: 'user delegated a "summarize my emails" agent for 24 hours with scope email:read',
1186
+ common_use_cases: ["agent-grant", "ai-delegation", "scoped-authorization"],
1187
+ typical_price_hint: "~320 sats \xB7 OFF by default (power-user)"
1188
+ },
1189
+ recovery_method_updated: {
1190
+ id: "recovery_method_updated",
1191
+ class: "A",
1192
+ label: "recovery method updated",
1193
+ fires_when: "a user changes their recovery email, recovery key, or social-recovery contacts",
1194
+ example: "user rotated their recovery email after a phone change",
1195
+ common_use_cases: ["recovery-rotation", "security-update"],
1196
+ typical_price_hint: "~160 sats (~$0.15)"
1197
+ },
1198
+ // ── Class B · action-bound ──
1199
+ payment_authorization: {
1200
+ id: "payment_authorization",
1201
+ class: "B",
1202
+ label: "payment authorized",
1203
+ fires_when: "a user authorizes a payment of underlying value (Lightning, on-chain BTC, or fiat-quoted)",
1204
+ example: "user paid $5.00 (\u22485260 sats) for a premium feature on your site",
1205
+ common_use_cases: ["payment", "checkout", "paywall", "subscription"],
1206
+ typical_price_hint: "0.75% of payment amount (percent_of_amount)"
1207
+ },
1208
+ scoped_action_authorization: {
1209
+ id: "scoped_action_authorization",
1210
+ class: "B",
1211
+ label: "scoped action authorized",
1212
+ fires_when: "a user takes a specific action your site bills on (post, vote, comment, claim) where each instance is meaningful",
1213
+ example: "user posted a long-form review that earns them sats from your editorial budget",
1214
+ common_use_cases: ["post", "vote", "comment", "claim", "submit"],
1215
+ typical_price_hint: "~100 sats (~$0.10)"
1216
+ },
1217
+ attest_verification_at_gate: {
1218
+ id: "attest_verification_at_gate",
1219
+ class: "B",
1220
+ label: "attest verification",
1221
+ fires_when: "your site's gate consulted the user's attest_tier and admitted them (counted only when admitted)",
1222
+ example: "admin gate checked attest_tier=bonded with bond\u226510k sats and granted access",
1223
+ common_use_cases: ["gate-check", "tier-gate", "sybil-filter"],
1224
+ typical_price_hint: "~280 sats (~$0.27) \xB7 OFF by default"
1225
+ },
1226
+ stamp_signing: {
1227
+ id: "stamp_signing",
1228
+ class: "B",
1229
+ label: "stamp signed",
1230
+ fires_when: "a user signs an oc-stamp envelope (provenance attestation, review credential, content stamp)",
1231
+ example: "user stamped their published recipe with their oc identity for downstream verification",
1232
+ common_use_cases: ["provenance", "review", "credential", "attestation"],
1233
+ typical_price_hint: "~55 sats (~$0.05) \xB7 OFF by default"
1234
+ },
1235
+ pledge_resolution: {
1236
+ id: "pledge_resolution",
1237
+ class: "B",
1238
+ label: "pledge resolved",
1239
+ fires_when: "an oc-pledge bonded commitment resolves (paid out, slashed, or refunded) on your surface",
1240
+ example: "user staked 50k sats on a prediction; market resolved and the pledge paid out",
1241
+ common_use_cases: ["pledge", "staking", "resolution", "commit-reveal"],
1242
+ typical_price_hint: "1% of pledge amount (percent_of_amount) \xB7 OFF by default"
1243
+ },
1244
+ // ── Class C · session ──
1245
+ session_creation: {
1246
+ id: "session_creation",
1247
+ class: "C",
1248
+ label: "session opened",
1249
+ fires_when: "a fresh authenticated session is opened for a returning user (sign-in within an existing session is FREE)",
1250
+ example: "user signed in after their last session expired; new session token issued",
1251
+ common_use_cases: ["sign-in", "session", "authenticate"],
1252
+ typical_price_hint: "~55 sats (~$0.05)"
1253
+ }
1254
+ };
1255
+ function subtypesForClass(cls) {
1256
+ return Object.values(EVENT_SUBTYPES).filter((m) => m.class === cls);
1257
+ }
1258
+ var ALL_EVENT_SUBTYPES = [
1259
+ ...subtypesForClass("A"),
1260
+ ...subtypesForClass("B"),
1261
+ ...subtypesForClass("C")
1262
+ ];
1263
+
912
1264
  // src/index.ts
913
1265
  var oc = { session, payment, event, config, webhook, federations, scope, family };
914
1266
 
1267
+ exports.ALL_EVENT_SUBTYPES = ALL_EVENT_SUBTYPES;
1268
+ exports.ARCHETYPE_TEMPLATES = ARCHETYPE_TEMPLATES;
1269
+ exports.EVENT_SUBTYPES = EVENT_SUBTYPES;
915
1270
  exports.MIN_INTEGRATOR_PRICE_SATS = MIN_INTEGRATOR_PRICE_SATS;
916
1271
  exports.MeClientError = MeClientError;
917
1272
  exports.OcSignInButton = OcSignInButton;
@@ -919,9 +1274,11 @@ exports.PLATFORM_FEE_POLICY = PLATFORM_FEE_POLICY;
919
1274
  exports.clearBearerToken = clearBearerToken;
920
1275
  exports.computeFees = computeFees;
921
1276
  exports.config = config;
1277
+ exports.configFromTemplate = fromTemplate;
922
1278
  exports.event = event;
923
1279
  exports.family = family;
924
1280
  exports.federations = federations;
1281
+ exports.getArchetypeTemplate = getArchetypeTemplate;
925
1282
  exports.getBearerToken = getBearerToken;
926
1283
  exports.getOrigin = getOrigin;
927
1284
  exports.oc = oc;
@@ -932,6 +1289,7 @@ exports.scope = scope;
932
1289
  exports.session = session;
933
1290
  exports.setBearerToken = setBearerToken;
934
1291
  exports.setOrigin = setOrigin;
1292
+ exports.subtypesForClass = subtypesForClass;
935
1293
  exports.validateIntegratorConfig = validateIntegratorConfig;
936
1294
  exports.webhook = webhook;
937
1295
  exports.withRateLimitRetry = withRateLimitRetry;