@powerhousedao/service-offering 0.0.4 → 0.0.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"document-models.d.ts","sourceRoot":"","sources":["../../document-models/document-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQ1D,eAAO,MAAM,cAAc,EAAE,mBAAmB,CAAC,GAAG,CAAC,EAOpD,CAAC"}
1
+ {"version":3,"file":"document-models.d.ts","sourceRoot":"","sources":["../../document-models/document-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAO1D,eAAO,MAAM,cAAc,EAAE,mBAAmB,CAAC,GAAG,CAAC,EAMpD,CAAC"}
@@ -2,13 +2,11 @@ import { Facet } from "./facet/module.js";
2
2
  import { ResourceInstance } from "./resource-instance/module.js";
3
3
  import { ResourceTemplate } from "./resource-template/module.js";
4
4
  import { ServiceOffering } from "./service-offering/module.js";
5
- import { ServiceSubscription } from "./service-subscription/module.js";
6
5
  import { SubscriptionInstance } from "./subscription-instance/module.js";
7
6
  export const documentModels = [
8
7
  Facet,
9
8
  ResourceInstance,
10
9
  ResourceTemplate,
11
10
  ServiceOffering,
12
- ServiceSubscription,
13
11
  SubscriptionInstance,
14
12
  ];
@@ -2,6 +2,5 @@ export { Facet } from "./facet/module.js";
2
2
  export { ResourceInstance } from "./resource-instance/module.js";
3
3
  export { ResourceTemplate } from "./resource-template/module.js";
4
4
  export { ServiceOffering } from "./service-offering/module.js";
5
- export { ServiceSubscription } from "./service-subscription/module.js";
6
5
  export { SubscriptionInstance } from "./subscription-instance/module.js";
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../document-models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../document-models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
@@ -2,5 +2,4 @@ export { Facet } from "./facet/module.js";
2
2
  export { ResourceInstance } from "./resource-instance/module.js";
3
3
  export { ResourceTemplate } from "./resource-template/module.js";
4
4
  export { ServiceOffering } from "./service-offering/module.js";
5
- export { ServiceSubscription } from "./service-subscription/module.js";
6
5
  export { SubscriptionInstance } from "./subscription-instance/module.js";
@@ -41,10 +41,10 @@ export declare const ResetPeriodSchema: z.ZodEnum<{
41
41
  }>;
42
42
  export declare const SubscriptionStatusSchema: z.ZodEnum<{
43
43
  ACTIVE: "ACTIVE";
44
- PENDING: "PENDING";
45
44
  CANCELLED: "CANCELLED";
46
45
  EXPIRING: "EXPIRING";
47
46
  PAUSED: "PAUSED";
47
+ PENDING: "PENDING";
48
48
  }>;
49
49
  export declare const TierPricingModeSchema: z.ZodEnum<{
50
50
  CALCULATED: "CALCULATED";
@@ -1 +1 @@
1
- {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/resources-services/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAqC5D,eAAO,MAAM,YAAY,GAAI,UAAU,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAwZxE,CAAC"}
1
+ {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../../../subgraphs/resources-services/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAqC5D,eAAO,MAAM,YAAY,GAAI,UAAU,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CA6ZxE,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import {} from "@powerhousedao/reactor-api";
2
2
  import { createAction } from "document-model/core";
3
3
  import { addFile } from "document-drive";
4
- import { ResourceInstance, ServiceSubscription, } from "@powerhousedao/service-offering/document-models";
4
+ import { ResourceInstance, SubscriptionInstance, } from "@powerhousedao/service-offering/document-models";
5
5
  export const getResolvers = (subgraph) => {
6
6
  const reactor = subgraph.reactor;
7
7
  return {
@@ -219,52 +219,65 @@ export const getResolvers = (subgraph) => {
219
219
  parentFolder: teamBuilderAdminDrive.state.global.nodes?.find((node) => node.kind === "folder")?.parentFolder,
220
220
  }));
221
221
  await reactor.addAction(builderProfileDoc.header.id, createAction("UPDATE_PROFILE", { name }, undefined, undefined, "global"));
222
- // create resource-instance doc inside the team-builder-admin drive
222
+ // create resource-instance and subscription-instance docs
223
223
  const resourceInstanceDoc = await reactor.addDocument("powerhouse/resource-instance");
224
- await reactor.addAction(teamBuilderAdminDrive.header.id, addFile({
225
- documentType: "powerhouse/resource-instance",
226
- id: resourceInstanceDoc.header.id,
227
- name: `${parsedName} Resource Instance`,
228
- parentFolder: teamBuilderAdminDrive.state.global.nodes?.find((node) => node.kind === "folder")?.parentFolder,
229
- }));
224
+ const subscriptionInstanceDoc = await reactor.addDocument("powerhouse/subscription-instance");
225
+ // resolve parent folders for both drives
226
+ const teamParentFolder = teamBuilderAdminDrive.state.global.nodes?.find((node) => node.kind === "folder")?.parentFolder;
227
+ const operatorDrive = await getOperatorDrive(reactor, resourceTemplateId);
228
+ if (!operatorDrive) {
229
+ throw new Error(`Operator drive not found for resource template ${resourceTemplateId}`);
230
+ }
231
+ const operatorParentFolder = operatorDrive.state.global.nodes?.find((node) => node.kind === "folder")?.parentFolder;
232
+ // batch add resource-instance and subscription-instance to team-builder-admin drive
233
+ await reactor.addActions(teamBuilderAdminDrive.header.id, [
234
+ addFile({
235
+ documentType: "powerhouse/resource-instance",
236
+ id: resourceInstanceDoc.header.id,
237
+ name: `${parsedName} Resource Instance`,
238
+ parentFolder: teamParentFolder,
239
+ }),
240
+ addFile({
241
+ documentType: "powerhouse/subscription-instance",
242
+ id: subscriptionInstanceDoc.header.id,
243
+ name: `${parsedName} Subscription Instance`,
244
+ parentFolder: teamParentFolder,
245
+ }),
246
+ ]);
247
+ // batch add resource-instance and subscription-instance to operator drive
248
+ await reactor.addActions(operatorDrive.header.id, [
249
+ addFile({
250
+ documentType: "powerhouse/resource-instance",
251
+ id: resourceInstanceDoc.header.id,
252
+ name: `${parsedName} Resource Instance`,
253
+ parentFolder: operatorParentFolder,
254
+ }),
255
+ addFile({
256
+ documentType: "powerhouse/subscription-instance",
257
+ id: subscriptionInstanceDoc.header.id,
258
+ name: `${parsedName} Subscription Instance`,
259
+ parentFolder: operatorParentFolder,
260
+ }),
261
+ ]);
262
+ // populate documents after all files are added to both drives
230
263
  await populateResourceInstance(reactor, resourceInstanceDoc.header.id, resourceTemplateId, builderProfileDoc.header.id, name);
231
- // create service-subscription doc inside the team-builder-admin drive
232
- const subscriptionDoc = await reactor.addDocument("powerhouse/service-subscription");
233
- await reactor.addAction(teamBuilderAdminDrive.header.id, addFile({
234
- documentType: "powerhouse/service-subscription",
235
- id: subscriptionDoc.header.id,
236
- name: `${parsedName} Service Subscription`,
237
- parentFolder: teamBuilderAdminDrive.state.global.nodes?.find((node) => node.kind === "folder")?.parentFolder,
238
- }));
239
264
  const now = new Date().toISOString();
240
- await reactor.addAction(subscriptionDoc.header.id, ServiceSubscription.actions.initializeSubscription({
241
- id: subscriptionDoc.header.id,
265
+ // find the selected tier to get its name and pricing details
266
+ const selectedTier = serviceOfferingState.tiers.find((t) => t.id === finalConfiguration.selectedTierId);
267
+ await reactor.addAction(subscriptionInstanceDoc.header.id, SubscriptionInstance.actions.initializeSubscription({
242
268
  customerId: builderProfileDoc.header.id,
243
269
  customerName: name,
244
270
  serviceOfferingId,
245
- serviceOfferingTitle: serviceOfferingState.title,
246
- resourceTemplateId,
247
- selectedTierId: finalConfiguration.selectedTierId,
271
+ resourceId: resourceInstanceDoc.header.id,
272
+ resourceLabel: name,
273
+ resourceThumbnailUrl: serviceOfferingState.thumbnailUrl,
274
+ tierName: selectedTier?.name || null,
275
+ tierPrice: selectedTier?.pricing?.amount ?? null,
276
+ tierCurrency: selectedTier?.pricing?.currency || null,
277
+ tierPricingMode: selectedTier?.pricingMode || null,
278
+ selectedBillingCycle: finalConfiguration.selectedBillingCycle || null,
279
+ globalCurrency: finalConfiguration.tierCurrency || null,
248
280
  createdAt: now,
249
- lastModified: now,
250
- }));
251
- // add resource-instance and subscription to operator's drive
252
- const operatorDrive = await getOperatorDrive(reactor, resourceTemplateId);
253
- if (!operatorDrive) {
254
- throw new Error(`Operator drive not found for resource template ${resourceTemplateId}`);
255
- }
256
- const operatorParentFolder = operatorDrive.state.global.nodes?.find((node) => node.kind === "folder")?.parentFolder;
257
- await reactor.addAction(operatorDrive.header.id, addFile({
258
- documentType: "powerhouse/resource-instance",
259
- id: resourceInstanceDoc.header.id,
260
- name: `${parsedName} Resource Instance`,
261
- parentFolder: operatorParentFolder,
262
- }));
263
- await reactor.addAction(operatorDrive.header.id, addFile({
264
- documentType: "powerhouse/service-subscription",
265
- id: subscriptionDoc.header.id,
266
- name: `${parsedName} Service Subscription`,
267
- parentFolder: operatorParentFolder,
268
281
  }));
269
282
  return {
270
283
  success: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@powerhousedao/service-offering",
3
3
  "description": "service offering document models",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "license": "AGPL-3.0-only",
6
6
  "type": "module",
7
7
  "files": [