@shaxpir/duiduidui-models 1.3.4 → 1.4.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.
@@ -0,0 +1,16 @@
1
+ import { Doc } from '@shaxpir/sharedb/lib/client';
2
+ import { ShareSync } from '../repo';
3
+ import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
4
+ export interface BillingPayload {
5
+ stripe_customer_id: string;
6
+ }
7
+ export interface BillingBody extends ContentBody {
8
+ meta: ContentMeta;
9
+ payload: BillingPayload;
10
+ }
11
+ export declare class Billing extends Content {
12
+ static makeBillingId(userId: ContentId): ContentId;
13
+ static create(userId: ContentId, payload: BillingPayload): Billing;
14
+ constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
15
+ get payload(): BillingPayload;
16
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Billing = void 0;
4
+ const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
5
+ const repo_1 = require("../repo");
6
+ const Content_1 = require("./Content");
7
+ const ContentKind_1 = require("./ContentKind");
8
+ class Billing extends Content_1.Content {
9
+ static makeBillingId(userId) {
10
+ return shaxpir_common_1.CachingHasher.makeMd5Base62Hash(userId + "-" + ContentKind_1.ContentKind.BILLING);
11
+ }
12
+ static create(userId, payload) {
13
+ const now = shaxpir_common_1.MultiClock.now();
14
+ const billingId = Billing.makeBillingId(userId);
15
+ return repo_1.ShareSyncFactory.get().createContent({
16
+ meta: {
17
+ ref: billingId,
18
+ kind: ContentKind_1.ContentKind.BILLING,
19
+ id: billingId,
20
+ owner: userId,
21
+ created_at: now,
22
+ updated_at: now
23
+ },
24
+ payload
25
+ });
26
+ }
27
+ constructor(doc, shouldAcquire, shareSync) {
28
+ super(doc, shouldAcquire, shareSync);
29
+ }
30
+ get payload() {
31
+ this.checkDisposed("Billing.payload");
32
+ return this.doc.data.payload;
33
+ }
34
+ }
35
+ exports.Billing = Billing;
@@ -1,6 +1,7 @@
1
1
  import { Doc } from '@shaxpir/sharedb/lib/client';
2
2
  import { CompactDateTime, MultiTime } from '@shaxpir/shaxpir-common';
3
3
  import { ShareSync } from '../repo';
4
+ import { BillingPayload } from './Billing';
4
5
  import { ContentKind } from './ContentKind';
5
6
  import { DevicePayload } from './Device';
6
7
  import { MediaPayload } from './Media';
@@ -35,7 +36,7 @@ export interface ContentMeta {
35
36
  created_at: MultiTime;
36
37
  updated_at: MultiTime;
37
38
  }
38
- export type ContentPayload = DevicePayload | MediaPayload | MetricPayload | ProfilePayload | ProgressPayload | SessionPayload | TermPayload | UserPayload | WorkspacePayload;
39
+ export type ContentPayload = BillingPayload | DevicePayload | MediaPayload | MetricPayload | ProfilePayload | ProgressPayload | SessionPayload | TermPayload | UserPayload | WorkspacePayload;
39
40
  export declare abstract class Content extends Model {
40
41
  static ID_LENGTH: number;
41
42
  constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
@@ -1,5 +1,6 @@
1
1
  export * from './ArrayView';
2
2
  export * from './BayesianScore';
3
+ export * from './Billing';
3
4
  export * from './ChangeModel';
4
5
  export * from './Content';
5
6
  export * from './ContentKind';
@@ -17,6 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./ArrayView"), exports);
19
19
  __exportStar(require("./BayesianScore"), exports);
20
+ __exportStar(require("./Billing"), exports);
20
21
  __exportStar(require("./ChangeModel"), exports);
21
22
  __exportStar(require("./Content"), exports);
22
23
  __exportStar(require("./ContentKind"), exports);
@@ -41,6 +41,7 @@ const client_1 = __importStar(require("@shaxpir/sharedb/lib/client"));
41
41
  const shaxpir_common_1 = require("@shaxpir/shaxpir-common");
42
42
  const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket"));
43
43
  const models_1 = require("../models");
44
+ const Billing_1 = require("../models/Billing");
44
45
  const Content_1 = require("../models/Content");
45
46
  const ContentKind_1 = require("../models/ContentKind");
46
47
  const Device_1 = require("../models/Device");
@@ -336,7 +337,10 @@ class ShareSync {
336
337
  }
337
338
  wrap(kind, doc, shouldAcquire) {
338
339
  const shareSync = this;
339
- if (kind === ContentKind_1.ContentKind.DEVICE) {
340
+ if (kind === ContentKind_1.ContentKind.BILLING) {
341
+ return new Billing_1.Billing(doc, shouldAcquire, shareSync);
342
+ }
343
+ else if (kind === ContentKind_1.ContentKind.DEVICE) {
340
344
  return new Device_1.Device(doc, shouldAcquire, shareSync);
341
345
  }
342
346
  else if (kind === ContentKind_1.ContentKind.MANIFEST) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.3.4",
3
+ "version": "1.4.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"